Sha256: 8cce5434b98f44a1c9e6796629446212d127a663c7dee330a6cdc61d53b558dd
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-18.0.0 | lib/ruby-vpi/float.rb |
ruby-vpi-17.0.0 | lib/ruby-vpi/float.rb |