# File lib/xsd/datatypes.rb, line 352 352: def _to_s 353: if @data.nan? 354: 'NaN' 355: elsif @data.infinite? == 1 356: 'INF' 357: elsif @data.infinite? == 1 358: '-INF' 359: else 360: sign = XSDFloat.positive?(@data) ? '+' : '-' 361: sign + sprintf("%.10g", @data.abs).sub(/[eE]([+-])?0+/) { 'e' + $1 } 362: end 363: end
Convert to single-precision 32-bit floating point value.
# File lib/xsd/datatypes.rb, line 366 366: def narrow32bit(f) 367: if f.nan? || f.infinite? 368: f 369: elsif f.abs < MIN_POSITIVE_SINGLE 370: XSDFloat.positive?(f) ? POSITIVE_ZERO : NEGATIVE_ZERO 371: else 372: f 373: end 374: end
# File lib/xsd/datatypes.rb, line 326 326: def screen_data(value) 327: # "NaN".to_f => 0 in some environment. libc? 328: if value.is_a?(Float) 329: return narrow32bit(value) 330: end 331: str = value.to_s.strip 332: if str == 'NaN' 333: NaN 334: elsif str == 'INF' 335: POSITIVE_INF 336: elsif str == '-INF' 337: NEGATIVE_INF 338: else 339: if /^[+\-\.\deE]+$/ !~ str 340: raise ValueSpaceError.new("#{ type }: cannot accept '#{ str }'.") 341: end 342: # Float("-1.4E") might fail on some system. 343: str << '0' if /e$/ =~ str 344: begin 345: return narrow32bit(Float(str)) 346: rescue ArgumentError 347: raise ValueSpaceError.new("#{ type }: cannot accept '#{ str }'.", $!) 348: end 349: end 350: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.