class XSD::XSDDouble
Ruby's Float is double-precision 64-bit floating point value.
Constants
- Type
Public Class Methods
new(value = nil)
click to toggle source
# File lib/xsd/datatypes.rb, line 386 def initialize(value = nil) init(Type, value) end
Private Instance Methods
_to_s()
click to toggle source
# File lib/xsd/datatypes.rb, line 422 def _to_s if @data.nan? 'NaN' elsif @data.infinite? == 1 'INF' elsif @data.infinite? == -1 '-INF' else sign = (1 / @data > 0.0) ? '+' : '-' sign + sprintf("%.16g", @data.abs).sub(/[eE]([+-])?0+/) { 'e' + $1 } end end
screen_data(value)
click to toggle source
# File lib/xsd/datatypes.rb, line 392 def screen_data(value) # "NaN".to_f => 0 in some environment. libc? if value.is_a?(Float) return value end str = value.to_s.strip if str == 'NaN' NaN elsif str == 'INF' POSITIVE_INF elsif str == '-INF' NEGATIVE_INF else begin return Float(str) rescue ArgumentError # '1.4e' cannot be parsed on some architecture. if /e\z/i =~ str begin return Float(str + '0') rescue ArgumentError raise ValueSpaceError.new("#{ type }: cannot accept '#{ str }'.", $!) end else raise ValueSpaceError.new("#{ type }: cannot accept '#{ str }'.", $!) end end end end