diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2012-06-04 17:04:47 -0700 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2012-06-04 17:04:47 -0700 |
| commit | 114168a551ffe4c429f9eeb2b2ccc09471b403a5 (patch) | |
| tree | 3b4a9483b6993a471de6a1096caaa92114e14755 /src | |
| parent | 2778058a8aaf119a032f689fb36d77f9787ab13d (diff) | |
| parent | 2c7cee8a1a7886691f5103a4319fca411408b500 (diff) | |
| download | mruby-114168a551ffe4c429f9eeb2b2ccc09471b403a5.tar.gz mruby-114168a551ffe4c429f9eeb2b2ccc09471b403a5.zip | |
Merge pull request #245 from pbosetti/tests
Added Math.sqrt() that was missing in math.c, and added relevant test case
Diffstat (limited to 'src')
| -rw-r--r-- | src/math.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/math.c b/src/math.c index b0d911573..eff2edcad 100644 --- a/src/math.c +++ b/src/math.c @@ -465,6 +465,25 @@ math_log10(mrb_state *mrb, mrb_value obj) /* * call-seq: + * Math.sqrt(numeric) -> float + * + * Returns the square root of <i>numeric</i>. + * + */ +static mrb_value +math_sqrt(mrb_state *mrb, mrb_value obj) +{ + mrb_float x; + + mrb_get_args(mrb, "f", &x); + x = sqrt(x); + + return mrb_float_value(x); +} + + +/* + * call-seq: * Math.cbrt(numeric) -> float * * Returns the cube root of <i>numeric</i>. @@ -646,6 +665,7 @@ mrb_init_math(mrb_state *mrb) mrb_define_module_function(mrb, mrb_math, "log", math_log, -1); mrb_define_module_function(mrb, mrb_math, "log2", math_log2, 1); mrb_define_module_function(mrb, mrb_math, "log10", math_log10, 1); + mrb_define_module_function(mrb, mrb_math, "sqrt", math_sqrt, 1); mrb_define_module_function(mrb, mrb_math, "cbrt", math_cbrt, 1); mrb_define_module_function(mrb, mrb_math, "frexp", math_frexp, 1); |
