class XSD::XSDFloat
Constants
- Type
Public Class Methods
new(value = nil)
click to toggle source
# File lib/xsd/datatypes.rb, line 320 def initialize(value = nil) init(Type, value) end
Private Class Methods
positive?(value)
click to toggle source
# File lib/xsd/datatypes.rb, line 376 def self.positive?(value) (1 / value) > 0.0 end
Private Instance Methods
_to_s()
click to toggle source
# File lib/xsd/datatypes.rb, line 352 def _to_s if @data.nan? 'NaN' elsif @data.infinite? == 1 'INF' elsif @data.infinite? == -1 '-INF' else sign = XSDFloat.positive?(@data) ? '+' : '-' sign + sprintf("%.10g", @data.abs).sub(/[eE]([+-])?0+/) { 'e' + $1 } end end
narrow32bit(f)
click to toggle source
Convert to single-precision 32-bit floating point value.
# File lib/xsd/datatypes.rb, line 366 def narrow32bit(f) if f.nan? || f.infinite? f elsif f.abs < MIN_POSITIVE_SINGLE XSDFloat.positive?(f) ? POSITIVE_ZERO : NEGATIVE_ZERO else f end end
screen_data(value)
click to toggle source
# File lib/xsd/datatypes.rb, line 326 def screen_data(value) # "NaN".to_f => 0 in some environment. libc? if value.is_a?(Float) return narrow32bit(value) end str = value.to_s.strip if str == 'NaN' NaN elsif str == 'INF' POSITIVE_INF elsif str == '-INF' NEGATIVE_INF else if /^[+\-\.\deE]+$/ !~ str raise ValueSpaceError.new("#{ type }: cannot accept '#{ str }'.") end # Float("-1.4E") might fail on some system. str << '0' if /e$/i =~ str begin return narrow32bit(Float(str)) rescue ArgumentError raise ValueSpaceError.new("#{ type }: cannot accept '#{ str }'.", $!) end end end