Class: Float

Inherits:
Object show all
Includes:
Decentworks::HexdigestSupport::NumericLike
Defined in:
lib/decentworks/hexdigest_support/numeric.rb

Instance Method Summary collapse

Methods included from Decentworks::HexdigestSupport::NumericLike

#to_hexdigest_source, #to_hexdigest_type

Instance Method Details

#to_hexdigest_rationalObject

正規化に用いる有理数

MEMO: #to_rではなく#to_sを経由して十進として読む。#to_rは2進の厳密値を返すため、 0.1が1/10ではなく3602879701896397/36028797018963968になり、 BigDecimal("0.1")やRational(1, 10)と別のダイジェストになってしまう

MEMO: Float#to_sは元の値へ復元できる最短の十進表記を返す。よって#==が真になる Float同士は必ず同じ有理数になり、異なるFloatが同じ有理数になることもない



30
# File 'lib/decentworks/hexdigest_support/numeric.rb', line 30

def to_hexdigest_rational = ::Kernel.Rational(to_s)