From 5d4e1831fafb5c2cb119d4b2cc5a704f3b9c1c55 Mon Sep 17 00:00:00 2001 From: Lukas Larsson Date: Wed, 27 Jul 2011 14:52:29 +0200 Subject: Add float vs integer comparison tests --- erts/emulator/test/float_SUITE.erl | 44 +++++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) (limited to 'erts/emulator/test') diff --git a/erts/emulator/test/float_SUITE.erl b/erts/emulator/test/float_SUITE.erl index 736510339f..e2e9b9120c 100644 --- a/erts/emulator/test/float_SUITE.erl +++ b/erts/emulator/test/float_SUITE.erl @@ -25,7 +25,7 @@ init_per_group/2,end_per_group/2, init_per_testcase/2,end_per_testcase/2, fpe/1,fp_drv/1,fp_drv_thread/1,denormalized/1,match/1, - bad_float_unpack/1]). + bad_float_unpack/1,cmp_zero/1, cmp_integer/1, cmp_bignum/1]). -export([otp_7178/1]). @@ -41,10 +41,10 @@ suite() -> [{ct_hooks,[ts_install_cth]}]. all() -> [fpe, fp_drv, fp_drv_thread, otp_7178, denormalized, - match, bad_float_unpack]. + match, bad_float_unpack, {group, comparison}]. groups() -> - []. + [{comparison, [parallel], [cmp_zero, cmp_integer, cmp_bignum]}]. init_per_suite(Config) -> Config. @@ -187,6 +187,44 @@ bad_float_unpack(Config) when is_list(Config) -> bad_float_unpack_match(<>) -> F; bad_float_unpack_match(<>) -> I. +cmp_zero(_Config) -> + cmp(0.5e-323,0). + +cmp_integer(_Config) -> + Axis = (1 bsl 53)-2.0, %% The point where floating points become unprecise + span_cmp(Axis,2,200), + cmp(Axis*Axis, round(Axis)). + +cmp_bignum(_Config) -> + span_cmp((1 bsl 58) - 1.0),%% Smallest bignum float + + %% Test I to I+1 bignum segment overflow + [span_cmp((1 bsl (32*I)) - 1.0) || I <- lists:seq(2,30)], + + cmp((1 bsl (64*16)) - 1, (1 bsl (64*15)) * 1.0), + ok. + +span_cmp(Axis) -> + span_cmp(Axis, 50). +span_cmp(Axis, Length) -> + span_cmp(Axis, round(Axis) bsr 52, Length). +span_cmp(Axis, Incr, Length) -> + [cmp(round(Axis*-1.0)+1+I*Incr,Axis*-1.0+I*Incr) + || I <- lists:seq((Length div 2)*-1,(Length div 2))], + [cmp(round(Axis)+1+I*Incr,Axis+I*Incr) || + I <- lists:seq((Length div 2)*-1,(Length div 2))]. + +cmp(Big,Small) -> + BigSmall = lists:flatten( + io_lib:format("~p > ~p",[Big,Small])), + SmallBig = lists:flatten( + io_lib:format("~p < ~p",[Big,Small])), + {_,_,_,true} = {Big,Small,BigSmall, + Big > Small}, + {_,_,_,false} = {Big,Small,SmallBig, + Big < Small}, + {BigSmall, SmallBig}. + id(I) -> I. start_node(Config) when is_list(Config) -> -- cgit v1.2.3 From 0ab6d70a34f5e2fbfdeb6235024a1d5e83cab64f Mon Sep 17 00:00:00 2001 From: Lukas Larsson Date: Tue, 11 Oct 2011 17:18:41 +0200 Subject: Expand tests for float and number comparison --- erts/emulator/test/float_SUITE.erl | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) (limited to 'erts/emulator/test') diff --git a/erts/emulator/test/float_SUITE.erl b/erts/emulator/test/float_SUITE.erl index e2e9b9120c..a8cc3b9a3f 100644 --- a/erts/emulator/test/float_SUITE.erl +++ b/erts/emulator/test/float_SUITE.erl @@ -193,7 +193,7 @@ cmp_zero(_Config) -> cmp_integer(_Config) -> Axis = (1 bsl 53)-2.0, %% The point where floating points become unprecise span_cmp(Axis,2,200), - cmp(Axis*Axis, round(Axis)). + cmp(Axis*Axis,round(Axis)). cmp_bignum(_Config) -> span_cmp((1 bsl 58) - 1.0),%% Smallest bignum float @@ -202,23 +202,39 @@ cmp_bignum(_Config) -> [span_cmp((1 bsl (32*I)) - 1.0) || I <- lists:seq(2,30)], cmp((1 bsl (64*16)) - 1, (1 bsl (64*15)) * 1.0), + [cmp((1 bsl (32*I)) - 1, (1 bsl (32*(I-2))) * 1.0) || I <- lists:seq(3,30)], ok. span_cmp(Axis) -> - span_cmp(Axis, 50). + span_cmp(Axis, 25). span_cmp(Axis, Length) -> span_cmp(Axis, round(Axis) bsr 52, Length). span_cmp(Axis, Incr, Length) -> - [cmp(round(Axis*-1.0)+1+I*Incr,Axis*-1.0+I*Incr) - || I <- lists:seq((Length div 2)*-1,(Length div 2))], - [cmp(round(Axis)+1+I*Incr,Axis+I*Incr) || - I <- lists:seq((Length div 2)*-1,(Length div 2))]. - -cmp(Big,Small) -> + [span_cmp(Axis, Incr, Length, 1 bsl (1 bsl I)) || I <- lists:seq(0,6)]. +span_cmp(Axis, Incr, Length, Diff) -> + [begin + cmp(round(Axis*-1.0)+Diff+I*Incr,Axis*-1.0+I*Incr), + cmp(Axis*-1.0+I*Incr,round(Axis*-1.0)-Diff+I*Incr) + end || I <- lists:seq((Length div 2)*-1,(Length div 2))], + [begin + cmp(round(Axis)+Diff+I*Incr,Axis+I*Incr), + cmp(Axis+I*Incr,round(Axis)-Diff+I*Incr) + end || I <- lists:seq((Length div 2)*-1,(Length div 2))]. + +cmp(Big,Small) when is_float(Big) -> + BigSmall = lists:flatten( + io_lib:format("~f > ~p",[Big,Small])), + SmallBig = lists:flatten( + io_lib:format("~f < ~p",[Big,Small])), + cmp(Big,Small,BigSmall,SmallBig); +cmp(Big,Small) when is_float(Small) -> BigSmall = lists:flatten( - io_lib:format("~p > ~p",[Big,Small])), + io_lib:format("~p > ~f",[Big,Small])), SmallBig = lists:flatten( - io_lib:format("~p < ~p",[Big,Small])), + io_lib:format("~p < ~f",[Big,Small])), + cmp(Big,Small,BigSmall,SmallBig). + +cmp(Big,Small,BigSmall,SmallBig) -> {_,_,_,true} = {Big,Small,BigSmall, Big > Small}, {_,_,_,false} = {Big,Small,SmallBig, -- cgit v1.2.3 From 0e88b9724ddd2d5ccd1def55ab2044e7665ca9e4 Mon Sep 17 00:00:00 2001 From: Lukas Larsson Date: Mon, 8 Aug 2011 18:46:56 +0200 Subject: Add tests for comparing large floats and small bignums --- erts/emulator/test/float_SUITE.erl | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) (limited to 'erts/emulator/test') diff --git a/erts/emulator/test/float_SUITE.erl b/erts/emulator/test/float_SUITE.erl index a8cc3b9a3f..bf0fbc70bc 100644 --- a/erts/emulator/test/float_SUITE.erl +++ b/erts/emulator/test/float_SUITE.erl @@ -203,6 +203,7 @@ cmp_bignum(_Config) -> cmp((1 bsl (64*16)) - 1, (1 bsl (64*15)) * 1.0), [cmp((1 bsl (32*I)) - 1, (1 bsl (32*(I-2))) * 1.0) || I <- lists:seq(3,30)], + [cmp((1 bsl (64*15)) * 1.0, (1 bsl (32*(I)))) || I <- lists:seq(1,29)], ok. span_cmp(Axis) -> @@ -222,24 +223,35 @@ span_cmp(Axis, Incr, Length, Diff) -> end || I <- lists:seq((Length div 2)*-1,(Length div 2))]. cmp(Big,Small) when is_float(Big) -> - BigSmall = lists:flatten( + BigGtSmall = lists:flatten( io_lib:format("~f > ~p",[Big,Small])), - SmallBig = lists:flatten( + BigLtSmall = lists:flatten( io_lib:format("~f < ~p",[Big,Small])), - cmp(Big,Small,BigSmall,SmallBig); + SmallGtBig = lists:flatten( + io_lib:format("~p > ~f",[Small,Big])), + SmallLtBig = lists:flatten( + io_lib:format("~p < ~f",[Small,Big])), + cmp(Big,Small,BigGtSmall,BigLtSmall,SmallGtBig,SmallLtBig); cmp(Big,Small) when is_float(Small) -> - BigSmall = lists:flatten( - io_lib:format("~p > ~f",[Big,Small])), - SmallBig = lists:flatten( - io_lib:format("~p < ~f",[Big,Small])), - cmp(Big,Small,BigSmall,SmallBig). - -cmp(Big,Small,BigSmall,SmallBig) -> - {_,_,_,true} = {Big,Small,BigSmall, + BigGtSmall = lists:flatten( + io_lib:format("~p > ~f",[Big,Small])), + BigLtSmall = lists:flatten( + io_lib:format("~p < ~f",[Big,Small])), + SmallGtBig = lists:flatten( + io_lib:format("~f > ~p",[Small,Big])), + SmallLtBig = lists:flatten( + io_lib:format("~f < ~p",[Small,Big])), + cmp(Big,Small,BigGtSmall,BigLtSmall,SmallGtBig,SmallLtBig). + +cmp(Big,Small,BigGtSmall,BigLtSmall,SmallGtBig,SmallLtBig) -> + {_,_,_,true} = {Big,Small,BigGtSmall, Big > Small}, - {_,_,_,false} = {Big,Small,SmallBig, + {_,_,_,false} = {Big,Small,BigLtSmall, Big < Small}, - {BigSmall, SmallBig}. + {_,_,_,false} = {Big,Small,SmallGtBig, + Small > Big}, + {_,_,_,true} = {Big,Small,SmallLtBig, + Small < Big}. id(I) -> I. -- cgit v1.2.3 From 3dc379948b1d7ce6c4f35f56df937603a6013f24 Mon Sep 17 00:00:00 2001 From: Lukas Larsson Date: Mon, 3 Oct 2011 19:08:20 +0200 Subject: Add tests for equality checking Test for checking equality on all float exponents Test in equality for all comparison tests --- erts/emulator/test/float_SUITE.erl | 41 ++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) (limited to 'erts/emulator/test') diff --git a/erts/emulator/test/float_SUITE.erl b/erts/emulator/test/float_SUITE.erl index bf0fbc70bc..46466427c5 100644 --- a/erts/emulator/test/float_SUITE.erl +++ b/erts/emulator/test/float_SUITE.erl @@ -198,13 +198,19 @@ cmp_integer(_Config) -> cmp_bignum(_Config) -> span_cmp((1 bsl 58) - 1.0),%% Smallest bignum float - %% Test I to I+1 bignum segment overflow + %% Test when the big num goes from I to I+1 in size [span_cmp((1 bsl (32*I)) - 1.0) || I <- lists:seq(2,30)], + %% Test bignum greater then largest float cmp((1 bsl (64*16)) - 1, (1 bsl (64*15)) * 1.0), + %% Test when num is much larger then float [cmp((1 bsl (32*I)) - 1, (1 bsl (32*(I-2))) * 1.0) || I <- lists:seq(3,30)], + %% Test when float is much larger than num [cmp((1 bsl (64*15)) * 1.0, (1 bsl (32*(I)))) || I <- lists:seq(1,29)], - ok. + + %% Test that all int == float works as they should + [true = 1 bsl N == (1 bsl N)*1.0 || N <- lists:seq(0, 1023)], + [true = (1 bsl N)*-1 == (1 bsl N)*-1.0 || N <- lists:seq(0, 1023)]. span_cmp(Axis) -> span_cmp(Axis, 25). @@ -212,6 +218,14 @@ span_cmp(Axis, Length) -> span_cmp(Axis, round(Axis) bsr 52, Length). span_cmp(Axis, Incr, Length) -> [span_cmp(Axis, Incr, Length, 1 bsl (1 bsl I)) || I <- lists:seq(0,6)]. +%% This function creates tests around number axis. Both <, > and == is tested +%% for both negative and positive numbers. +%% +%% Axis: The number around which to do the tests eg. (1 bsl 58) - 1.0 +%% Incr: How much to increment the test numbers inbetween each test. +%% Length: Length/2 is the number of Incr away from Axis to test on the +%% negative and positive plane. +%% Diff: How much the float and int should differ when comparing span_cmp(Axis, Incr, Length, Diff) -> [begin cmp(round(Axis*-1.0)+Diff+I*Incr,Axis*-1.0+I*Incr), @@ -227,23 +241,34 @@ cmp(Big,Small) when is_float(Big) -> io_lib:format("~f > ~p",[Big,Small])), BigLtSmall = lists:flatten( io_lib:format("~f < ~p",[Big,Small])), + BigEqSmall = lists:flatten( + io_lib:format("~f == ~p",[Big,Small])), SmallGtBig = lists:flatten( io_lib:format("~p > ~f",[Small,Big])), SmallLtBig = lists:flatten( io_lib:format("~p < ~f",[Small,Big])), - cmp(Big,Small,BigGtSmall,BigLtSmall,SmallGtBig,SmallLtBig); + SmallEqBig = lists:flatten( + io_lib:format("~p == ~f",[Small,Big])), + cmp(Big,Small,BigGtSmall,BigLtSmall,SmallGtBig,SmallLtBig, + SmallEqBig,BigEqSmall); cmp(Big,Small) when is_float(Small) -> BigGtSmall = lists:flatten( io_lib:format("~p > ~f",[Big,Small])), BigLtSmall = lists:flatten( io_lib:format("~p < ~f",[Big,Small])), + BigEqSmall = lists:flatten( + io_lib:format("~p == ~f",[Big,Small])), SmallGtBig = lists:flatten( io_lib:format("~f > ~p",[Small,Big])), SmallLtBig = lists:flatten( io_lib:format("~f < ~p",[Small,Big])), - cmp(Big,Small,BigGtSmall,BigLtSmall,SmallGtBig,SmallLtBig). + SmallEqBig = lists:flatten( + io_lib:format("~f == ~p",[Small,Big])), + cmp(Big,Small,BigGtSmall,BigLtSmall,SmallGtBig,SmallLtBig, + SmallEqBig,BigEqSmall). -cmp(Big,Small,BigGtSmall,BigLtSmall,SmallGtBig,SmallLtBig) -> +cmp(Big,Small,BigGtSmall,BigLtSmall,SmallGtBig,SmallLtBig, + SmallEqBig,BigEqSmall) -> {_,_,_,true} = {Big,Small,BigGtSmall, Big > Small}, {_,_,_,false} = {Big,Small,BigLtSmall, @@ -251,7 +276,11 @@ cmp(Big,Small,BigGtSmall,BigLtSmall,SmallGtBig,SmallLtBig) -> {_,_,_,false} = {Big,Small,SmallGtBig, Small > Big}, {_,_,_,true} = {Big,Small,SmallLtBig, - Small < Big}. + Small < Big}, + {_,_,_,false} = {Big,Small,SmallEqBig, + Small == Big}, + {_,_,_,false} = {Big,Small,BigEqSmall, + Big == Small}. id(I) -> I. -- cgit v1.2.3