Class: Float
Instance Method Summary collapse
-
#cbor_diagnostic(options = {}) ⇒ Object
do a little bit of JSON.stringify gaming (ECMA-262, 9.8.1).
-
#cbor_nan_toggle ⇒ Object
precondition: 1.0 < |self| < 2.0 or nan?.
Instance Method Details
#cbor_diagnostic(options = {}) ⇒ Object
do a little bit of JSON.stringify gaming (ECMA-262, 9.8.1)
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/cbor-diagnostic.rb', line 21 def cbor_diagnostic( = {}) # do a little bit of JSON.stringify gaming (ECMA-262, 9.8.1) if [:nan] && nan? pl = cbor_nan_toggle return "nan'#{('%a' % pl).gsub("+", "")}'" end a = abs if a < 1 && a >= 1e-6 inspect.sub(/(\d)[.](\d+)e-(\d+)/) {"0.#{"0" * ($3.to_i - 1)}#{$1}#{$2}"} else inspect.sub(/(e[+-])0+/) {$1} end end |
#cbor_nan_toggle ⇒ Object
precondition: 1.0 < |self| < 2.0 or nan?
2 3 4 5 6 |
# File 'lib/cbor-nan.rb', line 2 def cbor_nan_toggle # precondition: 1.0 < |self| < 2.0 or nan? a = [self].pack("G") a.setbyte(0, a.getbyte(0) ^ 0x40) a.unpack("G").first end |