class Float
Public Instance Methods
Source
# File lib/cbor-diagnostic.rb, line 21 def cbor_diagnostic(options = {}) # do a little bit of JSON.stringify gaming (ECMA-262, 9.8.1) if options[: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
Source
# 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