diff options
author | Lukas Larsson <[email protected]> | 2011-08-08 18:48:16 +0200 |
---|---|---|
committer | Lukas Larsson <[email protected]> | 2011-10-11 17:19:01 +0200 |
commit | 3b62e52f16ef72ce4224a61dc9e6bc7ab53234a1 (patch) | |
tree | e209ccdf3e5da51e6426a4ec085b77a74695eae8 /erts/emulator | |
parent | 0e88b9724ddd2d5ccd1def55ab2044e7665ca9e4 (diff) | |
download | otp-3b62e52f16ef72ce4224a61dc9e6bc7ab53234a1.tar.gz otp-3b62e52f16ef72ce4224a61dc9e6bc7ab53234a1.tar.bz2 otp-3b62e52f16ef72ce4224a61dc9e6bc7ab53234a1.zip |
Optimize comparison of huge floats and smaller bignums
Diffstat (limited to 'erts/emulator')
-rw-r--r-- | erts/emulator/beam/utils.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/erts/emulator/beam/utils.c b/erts/emulator/beam/utils.c index 5822b2e1d9..f296ccbadd 100644 --- a/erts/emulator/beam/utils.c +++ b/erts/emulator/beam/utils.c @@ -2686,9 +2686,12 @@ tailrecur_ne: && (f2.fd > (double) (MIN_SMALL - 1))) { // Float is a Sint j = big_sign(aw) ? -1 : 1; - } else if ( (pow(2.0,(big_arity(aw)-1.0)*D_EXP)-1.0) > fabs(f2.fd)) { - // If bignum size shows that it is bigger or smaller than the float + } else if ((pow(2.0,(big_arity(aw)-1.0)*D_EXP)-1.0) > fabs(f2.fd)) { + // If bignum size shows that it is bigger than the abs float j = big_sign(aw) ? -1 : 1; + } else if ((pow(2.0,(big_arity(aw))*D_EXP)-1.0) < fabs(f2.fd)) { + // If bignum size shows that it is smaller than the abs float + j = f2.fd < 0 ? 1 : -1; } else if (f2.fd < MAX_LOSSLESS_FLOAT && f2.fd > MIN_LOSSLESS_FLOAT) { // Float is within the no loss limit if (big_to_double(aw, &f1.fd) < 0) { @@ -2723,9 +2726,12 @@ tailrecur_ne: && (f1.fd > (double) (MIN_SMALL - 1))) { // Float is a Sint j = big_sign(bw) ? 1 : -1; } else if ((pow(2.0, (big_arity(bw) - 1.0) * D_EXP) - 1.0) > fabs(f1.fd)) { - // If bignum size shows that it is bigger than the float + // If bignum size shows that it is bigger than the abs float j = big_sign(bw) ? 1 : -1; - } else if (f1.fd < MAX_LOSSLESS_FLOAT && f1.fd >MIN_LOSSLESS_FLOAT) { + } else if ((pow(2.0,(big_arity(bw))*D_EXP)-1.0) < fabs(f1.fd)) { + // If bignum size shows that it is smaller than the abs float + j = f1.fd < 0 ? -1 : 1; + } else if (f1.fd < MAX_LOSSLESS_FLOAT && f1.fd > MIN_LOSSLESS_FLOAT) { // Float is within the no loss limit if (big_to_double(bw, &f2.fd) < 0) { j = big_sign(bw) ? 1 : -1; |