Class: Numeric
- Inherits:
-
Object
- Object
- Numeric
- Defined in:
- lib/fixedpnt.rb
Instance Method Summary collapse
-
#max_significant_bin_place ⇒ Object
Returns the max significant place of the binary representation (TODO: right wording?).
Instance Method Details
#max_significant_bin_place ⇒ Object
Returns the max significant place of the binary representation (TODO: right wording?). Negative sign means that most significant binary place is right from the binary point.
EXAMPLES: 33.max_significant_bin_place -> 6 (33 = 0b100001) (1.0/33).max_significant_bin_place -> -6 (1/33 = 0b0.000001111100001)
580 581 582 583 584 585 586 587 588 589 590 591 |
# File 'lib/fixedpnt.rb', line 580 def max_significant_bin_place( ) x = self.to_f.abs * 1.0000001 # 1.0000001 is for getting right values like 2**3 and 2**-3 TODO: Improve if x < 1 x = 1.0 / x sign = -1 else sign = 1 end x.to_i.to_s(2).size * sign end |