Sha256: d691a253d66c44343c267b40f88762572f32e8a310535b1a66b3bb2776c4f0d0
Contents?: true
Size: 747 Bytes
Versions: 2
Compression:
Stored size: 747 Bytes
Contents
# Library for hardware-related floating point operations. #-- # Copyright 2006-2007 Suraj N. Kurapati # See the file named LICENSE for details. class String # Converts this string into a floating point number using the given radix. # The default radix is 10. def to_f aRadix = 10 whole, frac = split('.', 2) whole = whole.to_i(aRadix).to_f if frac f = 0.0 frac.length.times do |i| power = i.next weight = aRadix ** -power digit = frac[i, 1].to_i(aRadix) f += digit * weight end f = -f if self =~ /^-/ whole += f end whole end end class Float # Returns the mantissa of this floating point number def mantissa f = abs f - f.floor end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
ruby-vpi-16.0.0 | lib/ruby-vpi/float.rb |
ruby-vpi-16.0.1 | lib/ruby-vpi/float.rb |