diff options
author | Marcus Arendt <[email protected]> | 2015-01-16 14:36:05 +0100 |
---|---|---|
committer | Marcus Arendt <[email protected]> | 2015-01-16 14:36:05 +0100 |
commit | 905824012cef106e7bd3796bff36a2aa04b58850 (patch) | |
tree | 6805bd7570965965e29c89e6673095bbd26599e1 /erts/emulator | |
parent | e52e4398a318293d57485c0a47f9c8e50a4b2b4b (diff) | |
parent | fdf09e81de5e7f1ecfe71f98b56c411073badae8 (diff) | |
download | otp-905824012cef106e7bd3796bff36a2aa04b58850.tar.gz otp-905824012cef106e7bd3796bff36a2aa04b58850.tar.bz2 otp-905824012cef106e7bd3796bff36a2aa04b58850.zip |
Merge branch 'oliv3/math_log2/OTP-12411'
* oliv3/math_log2/OTP-12411:
Add math:log2/1
Diffstat (limited to 'erts/emulator')
-rw-r--r-- | erts/emulator/beam/bif.tab | 1 | ||||
-rw-r--r-- | erts/emulator/beam/erl_math.c | 18 |
2 files changed, 19 insertions, 0 deletions
diff --git a/erts/emulator/beam/bif.tab b/erts/emulator/beam/bif.tab index aea3224342..1d0d214e77 100644 --- a/erts/emulator/beam/bif.tab +++ b/erts/emulator/beam/bif.tab @@ -194,6 +194,7 @@ bif math:erf/1 bif math:erfc/1 bif math:exp/1 bif math:log/1 +bif math:log2/1 bif math:log10/1 bif math:sqrt/1 bif math:atan2/2 diff --git a/erts/emulator/beam/erl_math.c b/erts/emulator/beam/erl_math.c index 16d4fdc09c..9b864628db 100644 --- a/erts/emulator/beam/erl_math.c +++ b/erts/emulator/beam/erl_math.c @@ -207,6 +207,24 @@ BIF_RETTYPE math_log_1(BIF_ALIST_1) return math_call_1(BIF_P, log, BIF_ARG_1); } +#ifdef HAVE_LOG2 +static double +log2_wrapper(double x) +{ + return log2(x); +} +#else +static double +log2_wrapper(double x) +{ + return log(x) / 0.6931471805599453; /* log(2.0); */ +} +#endif + +BIF_RETTYPE math_log2_1(BIF_ALIST_1) +{ + return math_call_1(BIF_P, log2_wrapper, BIF_ARG_1); +} BIF_RETTYPE math_log10_1(BIF_ALIST_1) { |