Class: Dhall::Double
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Expression
#&, #*, #+, #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_dhall ⇒ Object
1164
1165
1166
|
# File 'lib/dhall/ast.rb', line 1164
def self.as_dhall
Builtins[:Double]
end
|
Instance Method Details
#===(other) ⇒ Object
1176
1177
1178
|
# File 'lib/dhall/ast.rb', line 1176
def ===(other)
self == other || value === other
end
|
#as_json ⇒ Object
1193
1194
1195
|
# File 'lib/dhall/ast.rb', line 1193
def as_json
self
end
|
#coerce(other) ⇒ Object
1180
1181
1182
1183
|
# File 'lib/dhall/ast.rb', line 1180
def coerce(other)
return [other, self] if other.is_a?(Double)
[Double.new(value: other.to_f), self]
end
|
#eql?(other) ⇒ Boolean
1185
1186
1187
|
# File 'lib/dhall/ast.rb', line 1185
def eql?(other)
other.is_a?(Double) && to_cbor == other.to_cbor
end
|
#single? ⇒ Boolean
1189
1190
1191
|
# File 'lib/dhall/ast.rb', line 1189
def single?
[value].pack("g").unpack("g").first == value
end
|
#to_cbor(packer = nil) ⇒ Object
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
|
# File 'lib/dhall/ast.rb', line 1201
def to_cbor(packer=nil)
if [0, Float::INFINITY, -Float::INFINITY].include?(value) || value.nan?
return value.to_cbor(packer)
end
bytes = single? ? [0xFA, value].pack("Cg") : [0xFB, value].pack("CG")
if packer
packer.buffer.write(bytes)
packer
else
bytes
end
end
|
#to_f ⇒ Object
1172
1173
1174
|
# File 'lib/dhall/ast.rb', line 1172
def to_f
value
end
|
#to_json ⇒ Object
1197
1198
1199
|
# File 'lib/dhall/ast.rb', line 1197
def to_json
value.to_json
end
|
#to_s ⇒ Object
1168
1169
1170
|
# File 'lib/dhall/ast.rb', line 1168
def to_s
value.to_s
end
|