mbed I/F binding for mruby

Dependents:   mruby_mbed_web mirb_mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers math.c Source File

math.c

00001 /*
00002 ** math.c - Math module
00003 **
00004 ** See Copyright Notice in mruby.h
00005 */
00006 
00007 #include "mruby.h"
00008 #include "mruby/array.h"
00009 
00010 #include <math.h>
00011 
00012 static void
00013 domain_error(mrb_state *mrb, const char *func)
00014 {
00015   struct RClass *math = mrb_module_get(mrb, "Math");
00016   struct RClass *domainerror = mrb_class_get_under(mrb, math, "DomainError");
00017   mrb_value str = mrb_str_new_cstr(mrb, func);
00018   mrb_raisef(mrb, domainerror, "Numerical argument is out of domain - %S", str);
00019 }
00020 
00021 /* math functions not provided by Microsoft Visual C++ 2012 or older */
00022 #if defined _MSC_VER && _MSC_VER < 1800
00023 
00024 #include <float.h>
00025 
00026 #define MATH_TOLERANCE 1E-12
00027 
00028 double
00029 asinh(double x)
00030 {
00031   double xa, ya, y;
00032 
00033   /* Basic formula loses precision for x < 0, but asinh is an odd function */
00034   xa = fabs(x);
00035   if (xa > 3.16227E+18) {
00036     /* Prevent x*x from overflowing; basic formula reduces to log(2*x) */
00037     ya = log(xa) + 0.69314718055994530942;
00038   }
00039   else {
00040     /* Basic formula for asinh */
00041     ya = log(xa + sqrt(xa*xa + 1.0));
00042   }
00043 
00044   y = _copysign(ya, x);
00045   return y;
00046 }
00047 
00048 double
00049 acosh(double x)
00050 {
00051   double y;
00052 
00053   if (x > 3.16227E+18) {
00054     /* Prevent x*x from overflowing; basic formula reduces to log(2*x) */
00055     y = log(x) + 0.69314718055994530942;
00056   }
00057   else {
00058     /* Basic formula for acosh */
00059     y = log(x + sqrt(x*x - 1.0));
00060   }
00061 
00062   return y;
00063 }
00064 
00065 double
00066 atanh(double x)
00067 {
00068   double y;
00069 
00070   if (fabs(x) < 1E-2) {
00071     /* The sums 1+x and 1-x lose precision for small x.  Use the polynomial
00072        instead. */
00073     double x2 = x * x;
00074     y = x*(1.0 + x2*(1.0/3.0 + x2*(1.0/5.0 + x2*(1.0/7.0))));
00075   }
00076   else {
00077     /* Basic formula for atanh */
00078     y = 0.5 * (log(1.0+x) - log(1.0-x));
00079   }
00080 
00081   return y;
00082 }
00083 
00084 double
00085 cbrt(double x)
00086 {
00087   double xa, ya, y;
00088 
00089   /* pow(x, y) is undefined for x < 0 and y not an integer, but cbrt is an
00090      odd function */
00091   xa = fabs(x);
00092   ya = pow(xa, 1.0/3.0);
00093   y = _copysign(ya, x);
00094   return y;
00095 }
00096 
00097 /* Declaration of complementary Error function */
00098 double
00099 erfc(double x);
00100 
00101 /*
00102 ** Implementations of error functions
00103 ** credits to http://www.digitalmars.com/archives/cplusplus/3634.html
00104 */
00105 
00106 /* Implementation of Error function */
00107 double
00108 erf(double x)
00109 {
00110   static const double two_sqrtpi =  1.128379167095512574;
00111   double sum  = x;
00112   double term = x;
00113   double xsqr = x*x;
00114   int j= 1;
00115   if (fabs(x) > 2.2) {
00116     return 1.0 - erfc(x);
00117   }
00118   do {
00119     term *= xsqr/j;
00120     sum  -= term/(2*j+1);
00121     ++j;
00122     term *= xsqr/j;
00123     sum  += term/(2*j+1);
00124     ++j;
00125   } while (fabs(term/sum) > MATH_TOLERANCE);
00126   return two_sqrtpi*sum;
00127 }
00128 
00129 /* Implementation of complementary Error function */
00130 double
00131 erfc(double x)
00132 {
00133   static const double one_sqrtpi=  0.564189583547756287;
00134   double a = 1;
00135   double b = x;
00136   double c = x;
00137   double d = x*x+0.5;
00138   double q1;
00139   double q2 = b/d;
00140   double n = 1.0;
00141   double t;
00142   if (fabs(x) < 2.2) {
00143     return 1.0 - erf(x);
00144   }
00145   if (x < 0.0) { /*signbit(x)*/
00146     return 2.0 - erfc(-x);
00147   }
00148   do {
00149     t  = a*n+b*x;
00150     a  = b;
00151     b  = t;
00152     t  = c*n+d*x;
00153     c  = d;
00154     d  = t;
00155     n += 0.5;
00156     q1 = q2;
00157     q2 = b/d;
00158   } while (fabs(q1-q2)/q2 > MATH_TOLERANCE);
00159   return one_sqrtpi*exp(-x*x)*q2;
00160 }
00161 
00162 #endif
00163 
00164 #if (defined _MSC_VER && _MSC_VER < 1800) || defined __ANDROID__ || (defined __FreeBSD__  &&  __FreeBSD_version < 803000)
00165 
00166 double
00167 log2(double x)
00168 {
00169     return log10(x)/log10(2.0);
00170 }
00171 
00172 #endif
00173 
00174 /*
00175   TRIGONOMETRIC FUNCTIONS
00176 */
00177 
00178 /*
00179  *  call-seq:
00180  *     Math.sin(x)    -> float
00181  *
00182  *  Computes the sine of <i>x</i> (expressed in radians). Returns
00183  *  -1..1.
00184  */
00185 static mrb_value
00186 math_sin(mrb_state *mrb, mrb_value obj)
00187 {
00188   mrb_float x;
00189 
00190   mrb_get_args(mrb, "f", &x);
00191   x = sin(x);
00192 
00193   return mrb_float_value(mrb, x);
00194 }
00195 
00196 /*
00197  *  call-seq:
00198  *     Math.cos(x)    -> float
00199  *
00200  *  Computes the cosine of <i>x</i> (expressed in radians). Returns
00201  *  -1..1.
00202  */
00203 static mrb_value
00204 math_cos(mrb_state *mrb, mrb_value obj)
00205 {
00206   mrb_float x;
00207 
00208   mrb_get_args(mrb, "f", &x);
00209   x = cos(x);
00210 
00211   return mrb_float_value(mrb, x);
00212 }
00213 
00214 /*
00215  *  call-seq:
00216  *     Math.tan(x)    -> float
00217  *
00218  *  Returns the tangent of <i>x</i> (expressed in radians).
00219  */
00220 static mrb_value
00221 math_tan(mrb_state *mrb, mrb_value obj)
00222 {
00223   mrb_float x;
00224 
00225   mrb_get_args(mrb, "f", &x);
00226   x = tan(x);
00227 
00228   return mrb_float_value(mrb, x);
00229 }
00230 
00231 /*
00232   INVERSE TRIGONOMETRIC FUNCTIONS
00233 */
00234 
00235 /*
00236  *  call-seq:
00237  *     Math.asin(x)    -> float
00238  *
00239  *  Computes the arc sine of <i>x</i>. Returns -{PI/2} .. {PI/2}.
00240  */
00241 static mrb_value
00242 math_asin(mrb_state *mrb, mrb_value obj)
00243 {
00244   mrb_float x;
00245 
00246   mrb_get_args(mrb, "f", &x);
00247   if (x < -1.0 || x > 1.0) {
00248     domain_error(mrb, "asin");
00249   }
00250   x = asin(x);
00251 
00252   return mrb_float_value(mrb, x);
00253 }
00254 
00255 /*
00256  *  call-seq:
00257  *     Math.acos(x)    -> float
00258  *
00259  *  Computes the arc cosine of <i>x</i>. Returns 0..PI.
00260  */
00261 static mrb_value
00262 math_acos(mrb_state *mrb, mrb_value obj)
00263 {
00264   mrb_float x;
00265 
00266   mrb_get_args(mrb, "f", &x);
00267   if (x < -1.0 || x > 1.0) {
00268     domain_error(mrb, "acos");
00269   }
00270   x = acos(x);
00271 
00272   return mrb_float_value(mrb, x);
00273 }
00274 
00275 /*
00276  *  call-seq:
00277  *     Math.atan(x)    -> float
00278  *
00279  *  Computes the arc tangent of <i>x</i>. Returns -{PI/2} .. {PI/2}.
00280  */
00281 static mrb_value
00282 math_atan(mrb_state *mrb, mrb_value obj)
00283 {
00284   mrb_float x;
00285 
00286   mrb_get_args(mrb, "f", &x);
00287   x = atan(x);
00288 
00289   return mrb_float_value(mrb, x);
00290 }
00291 
00292 /*
00293  *  call-seq:
00294  *     Math.atan2(y, x)  -> float
00295  *
00296  *  Computes the arc tangent given <i>y</i> and <i>x</i>. Returns
00297  *  -PI..PI.
00298  *
00299  *    Math.atan2(-0.0, -1.0) #=> -3.141592653589793
00300  *    Math.atan2(-1.0, -1.0) #=> -2.356194490192345
00301  *    Math.atan2(-1.0, 0.0)  #=> -1.5707963267948966
00302  *    Math.atan2(-1.0, 1.0)  #=> -0.7853981633974483
00303  *    Math.atan2(-0.0, 1.0)  #=> -0.0
00304  *    Math.atan2(0.0, 1.0)   #=> 0.0
00305  *    Math.atan2(1.0, 1.0)   #=> 0.7853981633974483
00306  *    Math.atan2(1.0, 0.0)   #=> 1.5707963267948966
00307  *    Math.atan2(1.0, -1.0)  #=> 2.356194490192345
00308  *    Math.atan2(0.0, -1.0)  #=> 3.141592653589793
00309  *
00310  */
00311 static mrb_value
00312 math_atan2(mrb_state *mrb, mrb_value obj)
00313 {
00314   mrb_float x, y;
00315 
00316   mrb_get_args(mrb, "ff", &x, &y);
00317   x = atan2(x, y);
00318 
00319   return mrb_float_value(mrb, x);
00320 }
00321 
00322 
00323 
00324 /*
00325   HYPERBOLIC TRIG FUNCTIONS
00326 */
00327 /*
00328  *  call-seq:
00329  *     Math.sinh(x)    -> float
00330  *
00331  *  Computes the hyperbolic sine of <i>x</i> (expressed in
00332  *  radians).
00333  */
00334 static mrb_value
00335 math_sinh(mrb_state *mrb, mrb_value obj)
00336 {
00337   mrb_float x;
00338 
00339   mrb_get_args(mrb, "f", &x);
00340   x = sinh(x);
00341 
00342   return mrb_float_value(mrb, x);
00343 }
00344 
00345 /*
00346  *  call-seq:
00347  *     Math.cosh(x)    -> float
00348  *
00349  *  Computes the hyperbolic cosine of <i>x</i> (expressed in radians).
00350  */
00351 static mrb_value
00352 math_cosh(mrb_state *mrb, mrb_value obj)
00353 {
00354   mrb_float x;
00355 
00356   mrb_get_args(mrb, "f", &x);
00357   x = cosh(x);
00358 
00359   return mrb_float_value(mrb, x);
00360 }
00361 
00362 /*
00363  *  call-seq:
00364  *     Math.tanh()    -> float
00365  *
00366  *  Computes the hyperbolic tangent of <i>x</i> (expressed in
00367  *  radians).
00368  */
00369 static mrb_value
00370 math_tanh(mrb_state *mrb, mrb_value obj)
00371 {
00372   mrb_float x;
00373 
00374   mrb_get_args(mrb, "f", &x);
00375   x = tanh(x);
00376 
00377   return mrb_float_value(mrb, x);
00378 }
00379 
00380 
00381 /*
00382   INVERSE HYPERBOLIC TRIG FUNCTIONS
00383 */
00384 
00385 /*
00386  *  call-seq:
00387  *     Math.asinh(x)    -> float
00388  *
00389  *  Computes the inverse hyperbolic sine of <i>x</i>.
00390  */
00391 static mrb_value
00392 math_asinh(mrb_state *mrb, mrb_value obj)
00393 {
00394   mrb_float x;
00395 
00396   mrb_get_args(mrb, "f", &x);
00397 
00398   x = asinh(x);
00399 
00400   return mrb_float_value(mrb, x);
00401 }
00402 
00403 /*
00404  *  call-seq:
00405  *     Math.acosh(x)    -> float
00406  *
00407  *  Computes the inverse hyperbolic cosine of <i>x</i>.
00408  */
00409 static mrb_value
00410 math_acosh(mrb_state *mrb, mrb_value obj)
00411 {
00412   mrb_float x;
00413 
00414   mrb_get_args(mrb, "f", &x);
00415   if (x < 1.0) {
00416     domain_error(mrb, "acosh");
00417   }
00418   x = acosh(x);
00419 
00420   return mrb_float_value(mrb, x);
00421 }
00422 
00423 /*
00424  *  call-seq:
00425  *     Math.atanh(x)    -> float
00426  *
00427  *  Computes the inverse hyperbolic tangent of <i>x</i>.
00428  */
00429 static mrb_value
00430 math_atanh(mrb_state *mrb, mrb_value obj)
00431 {
00432   mrb_float x;
00433 
00434   mrb_get_args(mrb, "f", &x);
00435   if (x < -1.0 || x > 1.0) {
00436     domain_error(mrb, "atanh");
00437   }
00438   x = atanh(x);
00439 
00440   return mrb_float_value(mrb, x);
00441 }
00442 
00443 /*
00444   EXPONENTIALS AND LOGARITHMS
00445 */
00446 
00447 /*
00448  *  call-seq:
00449  *     Math.exp(x)    -> float
00450  *
00451  *  Returns e**x.
00452  *
00453  *    Math.exp(0)       #=> 1.0
00454  *    Math.exp(1)       #=> 2.718281828459045
00455  *    Math.exp(1.5)     #=> 4.4816890703380645
00456  *
00457  */
00458 static mrb_value
00459 math_exp(mrb_state *mrb, mrb_value obj)
00460 {
00461   mrb_float x;
00462 
00463   mrb_get_args(mrb, "f", &x);
00464   x = exp(x);
00465 
00466   return mrb_float_value(mrb, x);
00467 }
00468 
00469 /*
00470  *  call-seq:
00471  *     Math.log(numeric)    -> float
00472  *     Math.log(num,base)   -> float
00473  *
00474  *  Returns the natural logarithm of <i>numeric</i>.
00475  *  If additional second argument is given, it will be the base
00476  *  of logarithm.
00477  *
00478  *    Math.log(1)          #=> 0.0
00479  *    Math.log(Math::E)    #=> 1.0
00480  *    Math.log(Math::E**3) #=> 3.0
00481  *    Math.log(12,3)       #=> 2.2618595071429146
00482  *
00483  */
00484 static mrb_value
00485 math_log(mrb_state *mrb, mrb_value obj)
00486 {
00487   mrb_float x, base;
00488   int argc;
00489 
00490   argc = mrb_get_args(mrb, "f|f", &x, &base);
00491   if (x < 0.0) {
00492     domain_error(mrb, "log");
00493   }
00494   x = log(x);
00495   if (argc == 2) {
00496     if (base < 0.0) {
00497       domain_error(mrb, "log");
00498     }
00499     x /= log(base);
00500   }
00501   return mrb_float_value(mrb, x);
00502 }
00503 
00504 /*
00505  *  call-seq:
00506  *     Math.log2(numeric)    -> float
00507  *
00508  *  Returns the base 2 logarithm of <i>numeric</i>.
00509  *
00510  *    Math.log2(1)      #=> 0.0
00511  *    Math.log2(2)      #=> 1.0
00512  *    Math.log2(32768)  #=> 15.0
00513  *    Math.log2(65536)  #=> 16.0
00514  *
00515  */
00516 static mrb_value
00517 math_log2(mrb_state *mrb, mrb_value obj)
00518 {
00519   mrb_float x;
00520 
00521   mrb_get_args(mrb, "f", &x);
00522   if (x < 0.0) {
00523     domain_error(mrb, "log2");
00524   }
00525   x = log2(x);
00526 
00527   return mrb_float_value(mrb, x);
00528 }
00529 
00530 /*
00531  *  call-seq:
00532  *     Math.log10(numeric)    -> float
00533  *
00534  *  Returns the base 10 logarithm of <i>numeric</i>.
00535  *
00536  *    Math.log10(1)       #=> 0.0
00537  *    Math.log10(10)      #=> 1.0
00538  *    Math.log10(10**100) #=> 100.0
00539  *
00540  */
00541 static mrb_value
00542 math_log10(mrb_state *mrb, mrb_value obj)
00543 {
00544   mrb_float x;
00545 
00546   mrb_get_args(mrb, "f", &x);
00547   if (x < 0.0) {
00548     domain_error(mrb, "log10");
00549   }
00550   x = log10(x);
00551 
00552   return mrb_float_value(mrb, x);
00553 }
00554 
00555 /*
00556  *  call-seq:
00557  *     Math.sqrt(numeric)    -> float
00558  *
00559  *  Returns the square root of <i>numeric</i>.
00560  *
00561  */
00562 static mrb_value
00563 math_sqrt(mrb_state *mrb, mrb_value obj)
00564 {
00565   mrb_float x;
00566 
00567   mrb_get_args(mrb, "f", &x);
00568   if (x < 0.0) {
00569     domain_error(mrb, "sqrt");
00570   }
00571   x = sqrt(x);
00572 
00573   return mrb_float_value(mrb, x);
00574 }
00575 
00576 
00577 /*
00578  *  call-seq:
00579  *     Math.cbrt(numeric)    -> float
00580  *
00581  *  Returns the cube root of <i>numeric</i>.
00582  *
00583  *    -9.upto(9) {|x|
00584  *      p [x, Math.cbrt(x), Math.cbrt(x)**3]
00585  *    }
00586  *    #=>
00587  *    [-9, -2.0800838230519, -9.0]
00588  *    [-8, -2.0, -8.0]
00589  *    [-7, -1.91293118277239, -7.0]
00590  *    [-6, -1.81712059283214, -6.0]
00591  *    [-5, -1.7099759466767, -5.0]
00592  *    [-4, -1.5874010519682, -4.0]
00593  *    [-3, -1.44224957030741, -3.0]
00594  *    [-2, -1.25992104989487, -2.0]
00595  *    [-1, -1.0, -1.0]
00596  *    [0, 0.0, 0.0]
00597  *    [1, 1.0, 1.0]
00598  *    [2, 1.25992104989487, 2.0]
00599  *    [3, 1.44224957030741, 3.0]
00600  *    [4, 1.5874010519682, 4.0]
00601  *    [5, 1.7099759466767, 5.0]
00602  *    [6, 1.81712059283214, 6.0]
00603  *    [7, 1.91293118277239, 7.0]
00604  *    [8, 2.0, 8.0]
00605  *    [9, 2.0800838230519, 9.0]
00606  *
00607  */
00608 static mrb_value
00609 math_cbrt(mrb_state *mrb, mrb_value obj)
00610 {
00611   mrb_float x;
00612 
00613   mrb_get_args(mrb, "f", &x);
00614   x = cbrt(x);
00615 
00616   return mrb_float_value(mrb, x);
00617 }
00618 
00619 
00620 /*
00621  *  call-seq:
00622  *     Math.frexp(numeric)    -> [ fraction, exponent ]
00623  *
00624  *  Returns a two-element array containing the normalized fraction (a
00625  *  <code>Float</code>) and exponent (a <code>Fixnum</code>) of
00626  *  <i>numeric</i>.
00627  *
00628  *     fraction, exponent = Math.frexp(1234)   #=> [0.6025390625, 11]
00629  *     fraction * 2**exponent                  #=> 1234.0
00630  */
00631 static mrb_value
00632 math_frexp(mrb_state *mrb, mrb_value obj)
00633 {
00634   mrb_float x;
00635   int exp;
00636 
00637   mrb_get_args(mrb, "f", &x);
00638   x = frexp(x, &exp);
00639 
00640   return mrb_assoc_new(mrb, mrb_float_value(mrb, x), mrb_fixnum_value(exp));
00641 }
00642 
00643 /*
00644  *  call-seq:
00645  *     Math.ldexp(flt, int) -> float
00646  *
00647  *  Returns the value of <i>flt</i>*(2**<i>int</i>).
00648  *
00649  *     fraction, exponent = Math.frexp(1234)
00650  *     Math.ldexp(fraction, exponent)   #=> 1234.0
00651  */
00652 static mrb_value
00653 math_ldexp(mrb_state *mrb, mrb_value obj)
00654 {
00655   mrb_float x;
00656   mrb_int   i;
00657 
00658   mrb_get_args(mrb, "fi", &x, &i);
00659   x = ldexp(x, i);
00660 
00661   return mrb_float_value(mrb, x);
00662 }
00663 
00664 /*
00665  *  call-seq:
00666  *     Math.hypot(x, y)    -> float
00667  *
00668  *  Returns sqrt(x**2 + y**2), the hypotenuse of a right-angled triangle
00669  *  with sides <i>x</i> and <i>y</i>.
00670  *
00671  *     Math.hypot(3, 4)   #=> 5.0
00672  */
00673 static mrb_value
00674 math_hypot(mrb_state *mrb, mrb_value obj)
00675 {
00676   mrb_float x, y;
00677 
00678   mrb_get_args(mrb, "ff", &x, &y);
00679   x = hypot(x, y);
00680 
00681   return mrb_float_value(mrb, x);
00682 }
00683 
00684 /*
00685  * call-seq:
00686  *    Math.erf(x)  -> float
00687  *
00688  *  Calculates the error function of x.
00689  */
00690 static mrb_value
00691 math_erf(mrb_state *mrb, mrb_value obj)
00692 {
00693   mrb_float x;
00694 
00695   mrb_get_args(mrb, "f", &x);
00696   x = erf(x);
00697 
00698   return mrb_float_value(mrb, x);
00699 }
00700 
00701 
00702 /*
00703  * call-seq:
00704  *    Math.erfc(x)  -> float
00705  *
00706  *  Calculates the complementary error function of x.
00707  */
00708 static mrb_value
00709 math_erfc(mrb_state *mrb, mrb_value obj)
00710 {
00711   mrb_float x;
00712 
00713   mrb_get_args(mrb, "f", &x);
00714   x = erfc(x);
00715 
00716   return mrb_float_value(mrb, x);
00717 }
00718 
00719 /* ------------------------------------------------------------------------*/
00720 void
00721 mrb_mruby_math_gem_init(mrb_state* mrb)
00722 {
00723   struct RClass *mrb_math;
00724   mrb_math = mrb_define_module(mrb, "Math");
00725 
00726   mrb_define_class_under(mrb, mrb_math, "DomainError", mrb->eStandardError_class);
00727 
00728 #ifdef M_PI
00729   mrb_define_const(mrb, mrb_math, "PI", mrb_float_value(mrb, M_PI));
00730 #else
00731   mrb_define_const(mrb, mrb_math, "PI", mrb_float_value(mrb, atan(1.0)*4.0));
00732 #endif
00733 
00734 #ifdef M_E
00735   mrb_define_const(mrb, mrb_math, "E", mrb_float_value(mrb, M_E));
00736 #else
00737   mrb_define_const(mrb, mrb_math, "E", mrb_float_value(mrb, exp(1.0)));
00738 #endif
00739 
00740 #ifdef MRB_USE_FLOAT
00741   mrb_define_const(mrb, mrb_math, "TOLERANCE", mrb_float_value(mrb, 1e-5));
00742 #else
00743   mrb_define_const(mrb, mrb_math, "TOLERANCE", mrb_float_value(mrb, 1e-12));
00744 #endif
00745 
00746   mrb_define_module_function(mrb, mrb_math, "sin", math_sin, MRB_ARGS_REQ(1));
00747   mrb_define_module_function(mrb, mrb_math, "cos", math_cos, MRB_ARGS_REQ(1));
00748   mrb_define_module_function(mrb, mrb_math, "tan", math_tan, MRB_ARGS_REQ(1));
00749 
00750   mrb_define_module_function(mrb, mrb_math, "asin", math_asin, MRB_ARGS_REQ(1));
00751   mrb_define_module_function(mrb, mrb_math, "acos", math_acos, MRB_ARGS_REQ(1));
00752   mrb_define_module_function(mrb, mrb_math, "atan", math_atan, MRB_ARGS_REQ(1));
00753   mrb_define_module_function(mrb, mrb_math, "atan2", math_atan2, MRB_ARGS_REQ(2));
00754 
00755   mrb_define_module_function(mrb, mrb_math, "sinh", math_sinh, MRB_ARGS_REQ(1));
00756   mrb_define_module_function(mrb, mrb_math, "cosh", math_cosh, MRB_ARGS_REQ(1));
00757   mrb_define_module_function(mrb, mrb_math, "tanh", math_tanh, MRB_ARGS_REQ(1));
00758 
00759   mrb_define_module_function(mrb, mrb_math, "asinh", math_asinh, MRB_ARGS_REQ(1));
00760   mrb_define_module_function(mrb, mrb_math, "acosh", math_acosh, MRB_ARGS_REQ(1));
00761   mrb_define_module_function(mrb, mrb_math, "atanh", math_atanh, MRB_ARGS_REQ(1));
00762 
00763   mrb_define_module_function(mrb, mrb_math, "exp", math_exp, MRB_ARGS_REQ(1));
00764   mrb_define_module_function(mrb, mrb_math, "log", math_log, MRB_ARGS_REQ(1)|MRB_ARGS_OPT(1));
00765   mrb_define_module_function(mrb, mrb_math, "log2", math_log2, MRB_ARGS_REQ(1));
00766   mrb_define_module_function(mrb, mrb_math, "log10", math_log10, MRB_ARGS_REQ(1));
00767   mrb_define_module_function(mrb, mrb_math, "sqrt", math_sqrt, MRB_ARGS_REQ(1));
00768   mrb_define_module_function(mrb, mrb_math, "cbrt", math_cbrt, MRB_ARGS_REQ(1));
00769 
00770   mrb_define_module_function(mrb, mrb_math, "frexp", math_frexp, MRB_ARGS_REQ(1));
00771   mrb_define_module_function(mrb, mrb_math, "ldexp", math_ldexp, MRB_ARGS_REQ(2));
00772 
00773   mrb_define_module_function(mrb, mrb_math, "hypot", math_hypot, MRB_ARGS_REQ(2));
00774 
00775   mrb_define_module_function(mrb, mrb_math, "erf",  math_erf,  MRB_ARGS_REQ(1));
00776   mrb_define_module_function(mrb, mrb_math, "erfc", math_erfc, MRB_ARGS_REQ(1));
00777 }
00778 
00779 void
00780 mrb_mruby_math_gem_final(mrb_state* mrb)
00781 {
00782 }
00783