Class: Dhall::Double

Inherits:
Expression show all
Defined in:
lib/dhall/ast.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Expression

#&, #*, #+, #annotate, #as_dhall, #cache_key, #call, #concat, decode, #deep_merge, #deep_merge_type, #dhall_eq, #digest, #fetch, #fusion, #merge, #normalize, #resolve, #shift, #slice, #substitute, #to_binary, #to_proc, #|

Class Method Details

.as_dhallObject



1213
1214
1215
# File 'lib/dhall/ast.rb', line 1213

def self.as_dhall
	Builtins[:Double]
end

Instance Method Details

#===(other) ⇒ Object



1225
1226
1227
# File 'lib/dhall/ast.rb', line 1225

def ===(other)
	self == other || value === other
end

#as_jsonObject



1242
1243
1244
# File 'lib/dhall/ast.rb', line 1242

def as_json
	self
end

#coerce(other) ⇒ Object



1229
1230
1231
1232
# File 'lib/dhall/ast.rb', line 1229

def coerce(other)
	return [other, self] if other.is_a?(Double)
	[Double.new(value: other.to_f), self]
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


1234
1235
1236
# File 'lib/dhall/ast.rb', line 1234

def eql?(other)
	other.is_a?(Double) && to_cbor == other.to_cbor
end

#single?Boolean

Returns:

  • (Boolean)


1238
1239
1240
# File 'lib/dhall/ast.rb', line 1238

def single?
	[value].pack("g").unpack("g").first == value
end

#to_cbor(packer = nil) ⇒ Object



1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
# File 'lib/dhall/ast.rb', line 1250

def to_cbor(packer=nil)
	if [0, Float::INFINITY, -Float::INFINITY].include?(value) || value.nan?
		return value.to_cbor(packer)
	end

	# Dhall spec requires *not* using half-precision CBOR floats
	bytes = single? ? [0xFA, value].pack("Cg") : [0xFB, value].pack("CG")
	if packer
		packer.buffer.write(bytes)
		packer
	else
		bytes
	end
end

#to_fObject



1221
1222
1223
# File 'lib/dhall/ast.rb', line 1221

def to_f
	value
end

#to_jsonObject



1246
1247
1248
# File 'lib/dhall/ast.rb', line 1246

def to_json
	value.to_json
end

#to_sObject



1217
1218
1219
# File 'lib/dhall/ast.rb', line 1217

def to_s
	value.to_s
end