Class: Numeric

Inherits:
Object
  • Object
show all
Defined in:
lib/Dobjects/Numeric_extras.rb,
ext/Tioga/FigureMaker/generic.c

Overview

add some Numeric methods

Direct Known Subclasses

Integer

Instance Method Summary collapse

Instance Method Details

#acosObject

Math functions


9
10
11
# File 'lib/Dobjects/Numeric_extras.rb', line 9

def acos
    Math.acos(self)
end

#acoshObject


13
14
15
# File 'lib/Dobjects/Numeric_extras.rb', line 13

def acosh
    Math.acosh(self)
end

#as_exponent_of(y) ⇒ Object


101
102
103
# File 'lib/Dobjects/Numeric_extras.rb', line 101

def as_exponent_of(y)
    y**self
end

#asinObject


17
18
19
# File 'lib/Dobjects/Numeric_extras.rb', line 17

def asin
    Math.asin(self)
end

#asinhObject


21
22
23
# File 'lib/Dobjects/Numeric_extras.rb', line 21

def asinh
    Math.asinh(self)
end

#atanObject


25
26
27
# File 'lib/Dobjects/Numeric_extras.rb', line 25

def atan
    Math.atan(self)
end

#atan2(n) ⇒ Object


33
34
35
# File 'lib/Dobjects/Numeric_extras.rb', line 33

def atan2(n)
    Math.atan2(self,n)
end

#atanhObject


29
30
31
# File 'lib/Dobjects/Numeric_extras.rb', line 29

def atanh
    Math.atanh(self)
end

#cosObject


37
38
39
# File 'lib/Dobjects/Numeric_extras.rb', line 37

def cos
    Math.cos(self)
end

#coshObject


41
42
43
# File 'lib/Dobjects/Numeric_extras.rb', line 41

def cosh
    Math.cosh(self)
end

#expObject


45
46
47
# File 'lib/Dobjects/Numeric_extras.rb', line 45

def exp
    Math.exp(self)
end

#exp10Object


81
82
83
# File 'lib/Dobjects/Numeric_extras.rb', line 81

def exp10
    10**self
end

#invObject


85
86
87
# File 'lib/Dobjects/Numeric_extras.rb', line 85

def inv
    1/self
end

#logObject


49
50
51
# File 'lib/Dobjects/Numeric_extras.rb', line 49

def log
    Math.log(self)
end

#log10Object


53
54
55
# File 'lib/Dobjects/Numeric_extras.rb', line 53

def log10
    Math.log10(self)
end

#mod(y) ⇒ Object


129
130
131
# File 'lib/Dobjects/Numeric_extras.rb', line 129

def mod(y)
    self.modulo(y)
end

#negObject


77
78
79
# File 'lib/Dobjects/Numeric_extras.rb', line 77

def neg
    -self
end

#pow(y) ⇒ Object


93
94
95
# File 'lib/Dobjects/Numeric_extras.rb', line 93

def pow(y)
    self**y
end

#raised_to(y) ⇒ Object


97
98
99
# File 'lib/Dobjects/Numeric_extras.rb', line 97

def raised_to(y)
    self**y
end

#safe_acosObject


125
126
127
# File 'lib/Dobjects/Numeric_extras.rb', line 125

def safe_acos
    ((self > 1.0)? 1.0 : (self < -1.0)? -1.0 : self).acos
end

#safe_asinObject


121
122
123
# File 'lib/Dobjects/Numeric_extras.rb', line 121

def safe_asin
    ((self > 1.0)? 1.0 : (self < -1.0)? -1.0 : self).asin
end

#safe_inv(cutoff = 1e-99) ⇒ Object


113
114
115
# File 'lib/Dobjects/Numeric_extras.rb', line 113

def safe_inv(cutoff=1e-99)
    (self.abs > cutoff)? 1/self : (self > 0)? 1/cutoff : -1/cutoff
end

#safe_log(cutoff = 1e-99) ⇒ Object


105
106
107
# File 'lib/Dobjects/Numeric_extras.rb', line 105

def safe_log(cutoff=1e-99)
    ((self > cutoff)? self : cutoff).log
end

#safe_log10(cutoff = 1e-99) ⇒ Object


109
110
111
# File 'lib/Dobjects/Numeric_extras.rb', line 109

def safe_log10(cutoff=1e-99)
    ((self > cutoff)? self : cutoff).log10
end

#safe_sqrtObject


117
118
119
# File 'lib/Dobjects/Numeric_extras.rb', line 117

def safe_sqrt
    (self > 0.0)? self.sqrt : 0.0
end

#sinObject


57
58
59
# File 'lib/Dobjects/Numeric_extras.rb', line 57

def sin
    Math.sin(self)
end

#sinhObject


61
62
63
# File 'lib/Dobjects/Numeric_extras.rb', line 61

def sinh
    Math.sinh(self)
end

#sqrtObject


65
66
67
# File 'lib/Dobjects/Numeric_extras.rb', line 65

def sqrt
    Math.sqrt(self)
end

#tanObject


69
70
71
# File 'lib/Dobjects/Numeric_extras.rb', line 69

def tan
    Math.tan(self)
end

#tanhObject


73
74
75
# File 'lib/Dobjects/Numeric_extras.rb', line 73

def tanh
    Math.tanh(self)
end

#trim(cutoff = 1e-6) ⇒ Object


89
90
91
# File 'lib/Dobjects/Numeric_extras.rb', line 89

def trim(cutoff=1e-6)
    (self.abs < cutoff)? 0.0 : self
end