| Class | XSD::XSDDouble |
| In: |
lib/xsd/datatypes.rb
|
| Parent: | XSDAnySimpleType |
Ruby‘s Float is double-precision 64-bit floating point value.
| Type | = | QName.new(Namespace, DoubleLiteral) |
# File lib/xsd/datatypes.rb, line 372
372: def initialize(value = nil)
373: init(Type, value)
374: end
# File lib/xsd/datatypes.rb, line 408
408: def _to_s
409: if @data.nan?
410: 'NaN'
411: elsif @data.infinite? == 1
412: 'INF'
413: elsif @data.infinite? == -1
414: '-INF'
415: else
416: sign = (1 / @data > 0.0) ? '+' : '-'
417: sign + sprintf("%.16g", @data.abs).sub(/[eE]([+-])?0+/) { 'e' + $1 }
418: end
419: end
# File lib/xsd/datatypes.rb, line 378
378: def screen_data(value)
379: # "NaN".to_f => 0 in some environment. libc?
380: if value.is_a?(Float)
381: return value
382: end
383: str = value.to_s.strip
384: if str == 'NaN'
385: NaN
386: elsif str == 'INF'
387: POSITIVE_INF
388: elsif str == '-INF'
389: NEGATIVE_INF
390: else
391: begin
392: return Float(str)
393: rescue ArgumentError
394: # '1.4e' cannot be parsed on some architecture.
395: if /e\z/i =~ str
396: begin
397: return Float(str + '0')
398: rescue ArgumentError
399: raise ValueSpaceError.new("#{ type }: cannot accept '#{ str }'.")
400: end
401: else
402: raise ValueSpaceError.new("#{ type }: cannot accept '#{ str }'.")
403: end
404: end
405: end
406: end