Module: CMath
- Defined in:
- mrbgems/mruby-cmath/src/cmath.c
Class Method Summary collapse
- .acos ⇒ Object
- .acosh ⇒ Object
- .asin ⇒ Object
- .asinh ⇒ Object
- .atan ⇒ Object
- .atanh ⇒ Object
- .cos ⇒ Object
- .cosh ⇒ Object
- .exp ⇒ Object
-
.log ⇒ Object
log(z): return the natural logarithm of z, with branch cut along the negative real axis.
-
.log10 ⇒ Object
log10(z): return the base-10 logarithm of z, with branch cut along the negative real axis.
-
.log2 ⇒ Object
log2(z): return the base-2 logarithm of z, with branch cut along the negative real axis.
- .sin ⇒ Object
- .sinh ⇒ Object
-
.sqrt ⇒ Object
sqrt(z): return square root of z.
- .tan ⇒ Object
- .tanh ⇒ Object
Class Method Details
.acos ⇒ Object
.acosh ⇒ Object
.asin ⇒ Object
.asinh ⇒ Object
.atan ⇒ Object
.atanh ⇒ Object
.cos ⇒ Object
.cosh ⇒ Object
.exp ⇒ Object
.log ⇒ Object
log(z): return the natural logarithm of z, with branch cut along the negative real axis
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'mrbgems/mruby-cmath/src/cmath.c', line 145 DEF_CMATH_METHOD(exp) /* log(z): return the natural logarithm of z, with branch cut along the negative real axis */ static mrb_value cmath_log(mrb_state *mrb, mrb_value self) { mrb_value z; mrb_float base; mrb_float real, imag; mrb_int n = mrb_get_args(mrb, "o|f", &z, &base); #ifndef M_E #define M_E F(exp)(1.0) #endif if (n == 1) base = M_E; if (cmath_get_complex(mrb, z, &real, &imag) || real < 0.0) { mrb_complex c = CX(real,imag); c = FC(log)(c); if (n == 2) c = CXDIVc(c, FC(log)(CX(base,0))); return mrb_complex_new(mrb, creal(c), cimag(c)); } if (n == 1) return mrb_float_value(mrb, F(log)(real)); return mrb_float_value(mrb, F(log)(real)/F(log)(base)); } |
.log10 ⇒ Object
log10(z): return the base-10 logarithm of z, with branch cut along the negative real axis
172 173 174 175 176 177 178 179 180 181 182 |
# File 'mrbgems/mruby-cmath/src/cmath.c', line 172 static mrb_value cmath_log10(mrb_state *mrb, mrb_value self) { mrb_value z = mrb_get_arg1(mrb); mrb_float real, imag; if (cmath_get_complex(mrb, z, &real, &imag) || real < 0.0) { mrb_complex c = CX(real,imag); c = CXDIVf(FC(log)(c),log(10)); return mrb_complex_new(mrb, creal(c), cimag(c)); } return mrb_float_value(mrb, F(log10)(real)); } |
.log2 ⇒ Object
log2(z): return the base-2 logarithm of z, with branch cut along the negative real axis
185 186 187 188 189 190 191 192 193 194 195 |
# File 'mrbgems/mruby-cmath/src/cmath.c', line 185 static mrb_value cmath_log2(mrb_state *mrb, mrb_value self) { mrb_value z = mrb_get_arg1(mrb); mrb_float real, imag; if (cmath_get_complex(mrb, z, &real, &imag) || real < 0.0) { mrb_complex c = CX(real,imag); c = CXDIVf(FC(log)(c),log(2.0)); return mrb_complex_new(mrb, creal(c), cimag(c)); } return mrb_float_value(mrb, F(log2)(real)); } |
.sin ⇒ Object
.sinh ⇒ Object
.sqrt ⇒ Object
sqrt(z): return square root of z
198 199 200 201 202 203 204 205 206 207 208 |
# File 'mrbgems/mruby-cmath/src/cmath.c', line 198 static mrb_value cmath_sqrt(mrb_state *mrb, mrb_value self) { mrb_value z = mrb_get_arg1(mrb); mrb_float real, imag; if (cmath_get_complex(mrb, z, &real, &imag) || real < 0.0) { mrb_complex c = CX(real,imag); c = FC(sqrt)(c); return mrb_complex_new(mrb, creal(c), cimag(c)); } return mrb_float_value(mrb, F(sqrt)(real)); } |