aboutsummaryrefslogtreecommitdiffstats
path: root/lib/compiler
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2016-11-03 09:58:32 +0100
committerBjörn Gustavsson <[email protected]>2016-11-03 09:58:32 +0100
commit214aba4561eb09020379cb4d7da7e6fffe2873ab (patch)
treeb02f066ce3ebb5e055c3bc60454b51291f25f08a /lib/compiler
parent38e1f98a0a4729357c3669a5c5e2f93ad5ab1d90 (diff)
parent39d08368a04aa0459390ac070f3570e10cffe219 (diff)
downloadotp-214aba4561eb09020379cb4d7da7e6fffe2873ab.tar.gz
otp-214aba4561eb09020379cb4d7da7e6fffe2873ab.tar.bz2
otp-214aba4561eb09020379cb4d7da7e6fffe2873ab.zip
Merge branch 'gandrade/fmod/PR-1216/OTP-14000'
* gandrade/fmod/PR-1216/OTP-14000: Add test cases for math:fmod/2 BIF Support math:fmod/2 BIF on compiler Add math:fmod/2 BIF
Diffstat (limited to 'lib/compiler')
-rw-r--r--lib/compiler/src/beam_type.erl1
-rw-r--r--lib/compiler/src/beam_validator.erl1
-rw-r--r--lib/compiler/src/erl_bifs.erl1
-rw-r--r--lib/compiler/test/float_SUITE.erl7
4 files changed, 10 insertions, 0 deletions
diff --git a/lib/compiler/src/beam_type.erl b/lib/compiler/src/beam_type.erl
index b4776294be..d324580cba 100644
--- a/lib/compiler/src/beam_type.erl
+++ b/lib/compiler/src/beam_type.erl
@@ -594,6 +594,7 @@ is_math_bif(atan2, 2) -> true;
is_math_bif(pow, 2) -> true;
is_math_bif(ceil, 1) -> true;
is_math_bif(floor, 1) -> true;
+is_math_bif(fmod, 2) -> true;
is_math_bif(pi, 0) -> true;
is_math_bif(_, _) -> false.
diff --git a/lib/compiler/src/beam_validator.erl b/lib/compiler/src/beam_validator.erl
index 6e53f53a20..5659077c5d 100644
--- a/lib/compiler/src/beam_validator.erl
+++ b/lib/compiler/src/beam_validator.erl
@@ -1646,6 +1646,7 @@ return_type_math(atan2, 2) -> {float,[]};
return_type_math(pow, 2) -> {float,[]};
return_type_math(ceil, 1) -> {float,[]};
return_type_math(floor, 1) -> {float,[]};
+return_type_math(fmod, 2) -> {float,[]};
return_type_math(pi, 0) -> {float,[]};
return_type_math(F, A) when is_atom(F), is_integer(A), A >= 0 -> term.
diff --git a/lib/compiler/src/erl_bifs.erl b/lib/compiler/src/erl_bifs.erl
index 831730ba48..d60f73d421 100644
--- a/lib/compiler/src/erl_bifs.erl
+++ b/lib/compiler/src/erl_bifs.erl
@@ -138,6 +138,7 @@ is_pure(math, erf, 1) -> true;
is_pure(math, erfc, 1) -> true;
is_pure(math, exp, 1) -> true;
is_pure(math, floor, 1) -> true;
+is_pure(math, fmod, 2) -> true;
is_pure(math, log, 1) -> true;
is_pure(math, log2, 1) -> true;
is_pure(math, log10, 1) -> true;
diff --git a/lib/compiler/test/float_SUITE.erl b/lib/compiler/test/float_SUITE.erl
index 0ebc71eb9b..08c3dd8593 100644
--- a/lib/compiler/test/float_SUITE.erl
+++ b/lib/compiler/test/float_SUITE.erl
@@ -155,6 +155,13 @@ math_functions(Config) when is_list(Config) ->
5.0 = math:floor(id(5.4)),
6.0 = math:ceil(id(5.4)),
+ 0.0 = math:fmod(42, 42),
+ 0.25 = math:fmod(1, 0.75),
+ -1.0 = math:fmod(-4.0, 1.5),
+ -0.375 = math:fmod(-3.0, -0.875),
+ 0.125 = math:fmod(8.125, -4),
+ {'EXIT',{badarith,_}} = (catch math:fmod(5.0, 0.0)),
+
%% Only for coverage (of beam_type.erl).
{'EXIT',{undef,_}} = (catch math:fnurfla(0)),
{'EXIT',{undef,_}} = (catch math:fnurfla(0, 0)),