Class: Numeric

Inherits:
Object show all
Defined in:
lib/feldtruby/float.rb

Instance Method Summary collapse

Instance Method Details

#protected_division_with(denom) ⇒ Object



9
10
11
12
# File 'lib/feldtruby/float.rb', line 9

def protected_division_with(denom)
	return 0.0 if denom == 0
	self / denom
end

#ratio_diff_vs(other) ⇒ Object



14
15
16
# File 'lib/feldtruby/float.rb', line 14

def ratio_diff_vs(other)
	(self - other).protected_division_with(other)
end

#round_to_decimals(numDecimals = 2) ⇒ Object



4
5
6
7
# File 'lib/feldtruby/float.rb', line 4

def round_to_decimals(numDecimals = 2)
	factor = 10**numDecimals
	(self * factor).round / factor.to_f
end

#signif(numDigits = 3) ⇒ Object

Change to a float with a given number of significant digits.



19
20
21
# File 'lib/feldtruby/float.rb', line 19

def signif(numDigits = 3)
	self.to_f.signif(numDigits)
end

#to_significant_digits(numDigits = 3) ⇒ Object

Change to a float with a given number of significant digits.



24
25
26
# File 'lib/feldtruby/float.rb', line 24

def to_significant_digits(numDigits = 3)
	self.to_f.to_significant_digits(numDigits)
end