-
Notifications
You must be signed in to change notification settings - Fork 561
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unexpected interaction between binary multiplication operator and Test::More::cmp_ok() #14718
Comments
From @jkeenanToday I was bitten by an unexpected interaction between Perl's binary multiplication operator (*) and Test::More::cmp_ok(). I got expected results only on very old versions of Perl and Test::More. Though I was able to compensate for this problem on newer versions of Perl and Test::More, the fact that I got unexpected results suggests either the presence of a bug or the need for some cautionary documentation somewhere. The situation: I needed to test whether I was getting expected values of prices stored in US dollars (USD) but converted to Japanese yen (JPY). For testing purposes, I assumed that the JPY/USD exchange rate was 8:1. Consider the program attached, 'cmp_ok.pl', which illustrates four different usages of Test::More::cmp_ok(). Cet. par., I would expect all four to PASS and, when run with perl-5.6.2 and the version of Test::More that came with that perl, 0.47, the do. ##### However, when I switch to perl-5.8.9 and the version of Test::More that came with that perl, 0.80, the third test FAILs. In the third test, I calculate the expected JPY price by multiplying the USD price by the JPY/USD exchange rate -- multiplication of two floats -- and assign the result to $calculated_jpy, which I then use in the next instance of 'cmp_ok'. The output of 'cmp_ok' suggests that the two values are not mathematically equal even though the 'got' and 'expected' outputs are identical! $ perlbrew switch perl-5.8.9 Testing on more recent perl/Test::More combinations, I get the same results as I did on 5.8.9/0.80. Example: ##### Note that when I sprintf-ed the product of the multiplication and used the result in 'cmp_ok', I got the expected PASS (fourth instance in each perl version). I haven't yet had time to figure out whether the change in behavior between 5.6.2/0.47 and 5.8.9/0.80 occurred in perl or in Test::More. But I suspect that this surprising behavior needs to be documented somewhere. Recommendations? Thank you very much. |
From @jkeenanToday I was bitten by an unexpected interaction between Perl's binary multiplication operator (*) and Test::More::cmp_ok(). I got expected results only on very old versions of Perl and Test::More. Though I was able to compensate for this problem on newer versions of Perl and Test::More, the fact that I got unexpected results suggests either the presence of a bug or the need for some cautionary documentation somewhere. The situation: I needed to test whether I was getting expected values of prices stored in US dollars (USD) but converted to Japanese yen (JPY). For testing purposes, I assumed that the JPY/USD exchange rate was 8:1. Consider the program attached, 'cmp_ok.pl', which illustrates four different usages of Test::More::cmp_ok(). Cet. par., I would expect all four to PASS and, when run with perl-5.6.2 and the version of Test::More that came with that perl, 0.47, the do. ##### However, when I switch to perl-5.8.9 and the version of Test::More that came with that perl, 0.80, the third test FAILs. In the third test, I calculate the expected JPY price by multiplying the USD price by the JPY/USD exchange rate -- multiplication of two floats -- and assign the result to $calculated_jpy, which I then use in the next instance of 'cmp_ok'. The output of 'cmp_ok' suggests that the two values are not mathematically equal even though the 'got' and 'expected' outputs are identical! $ perlbrew switch perl-5.8.9 Testing on more recent perl/Test::More combinations, I get the same results as I did on 5.8.9/0.80. Example: ##### Note that when I sprintf-ed the product of the multiplication and used the result in 'cmp_ok', I got the expected PASS (fourth instance in each perl version). I haven't yet had time to figure out whether the change in behavior between 5.6.2/0.47 and 5.8.9/0.80 occurred in perl or in Test::More. But I suspect that this surprising behavior needs to be documented somewhere. Recommendations? Thank you very much. |
From @jkeenanSummary of my perl5 (revision 5 version 20 subversion 1) configuration: Characteristics of this binary (from libperl): |
From @jkeenanAttached the wrong file. Now attaching the 'cmp_ok.pl' program. |
From [Unknown Contact. See original ticket]Attached the wrong file. Now attaching the 'cmp_ok.pl' program. |
From zefram@fysh.orgJames E Keenan wrote:
It's nothing to do with cmp_ok, and little to do with *; it's just $ perl5.8.0 -lwe 'printf "%.70f\n" x 2, 1.68, 8 * 0.21' Both versions agree on the floating point conversion of 0.21, and indeed We already know the decimal->float conversion is broken; see [perl $ perl5.8.0 perl -lwe 'printf "%f\n", 1180591620717411303424.0' So I suspect that the dodgy conversion of 1.68 is merely another example -zefram |
The RT System itself - Status changed from 'new' to 'open' |
@iabyn - Status changed from 'open' to 'rejected' |
Migrated from rt.perl.org#125266 (status was 'rejected')
Searchable as RT125266$
The text was updated successfully, but these errors were encountered: