cos(3*pi(cpp_bin_float_50>()/2)) does not give correct value. Only cos(pi(cpp_bin_float_50>()/2)) gives correct value. All odd multiples of cos(pi/2) do not give correct value. The issue with sin() as well. Anshu
On 16/01/2020 15:08, anshu khare via Boost wrote:
cos(3*pi(cpp_bin_float_50>()/2)) does not give correct value.
What do you call "correct"? If you're expecting an exact 0 result, then you're going to be disappointed - likewise with double which also does not yield an exact 0 in your test case (at least on msvc). John.
Only cos(pi(cpp_bin_float_50>()/2)) gives correct value. All odd multiples of cos(pi/2) do not give correct value.
The issue with sin() as well.
Anshu
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Cos(pi/2) gives an exact zero. Cos(3*pi/2) gives a value less than €. But cos(7*pi/2) gives a large negative value which is not less than €. Anshu On Thu, 16 Jan, 2020, 11:29 PM John Maddock via Boost, < boost@lists.boost.org> wrote:
On 16/01/2020 15:08, anshu khare via Boost wrote:
cos(3*pi(cpp_bin_float_50>()/2)) does not give correct value.
What do you call "correct"? If you're expecting an exact 0 result, then you're going to be disappointed - likewise with double which also does not yield an exact 0 in your test case (at least on msvc).
John.
Only cos(pi(cpp_bin_float_50>()/2)) gives correct value. All odd multiples of cos(pi/2) do not give correct value.
The issue with sin() as well.
Anshu
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
That's because pi is not pi but an approximation of it. When you multiply
you amplify the error.
On Thu, Jan 16, 2020, 18:48 anshu khare via Boost
Cos(pi/2) gives an exact zero. Cos(3*pi/2) gives a value less than €. But cos(7*pi/2) gives a large negative value which is not less than €.
Anshu
On Thu, 16 Jan, 2020, 11:29 PM John Maddock via Boost, < boost@lists.boost.org> wrote:
On 16/01/2020 15:08, anshu khare via Boost wrote:
cos(3*pi(cpp_bin_float_50>()/2)) does not give correct value.
What do you call "correct"? If you're expecting an exact 0 result, then you're going to be disappointed - likewise with double which also does not yield an exact 0 in your test case (at least on msvc).
John.
Only cos(pi(cpp_bin_float_50>()/2)) gives correct value. All odd multiples of cos(pi/2) do not give correct value.
The issue with sin() as well.
Anshu
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
On running cos(3*pi/2) , cos(5*pi/2) , cos(7*pi/2) , cos(9*pi/2) all give the same answer, which is less than epsilon except cos(7*pi/2) which gives a highly negative value. On Fri, 17 Jan, 2020, 5:41 AM Damian Vicino via Boost, < boost@lists.boost.org> wrote:
That's because pi is not pi but an approximation of it. When you multiply you amplify the error.
On Thu, Jan 16, 2020, 18:48 anshu khare via Boost
wrote: Cos(pi/2) gives an exact zero. Cos(3*pi/2) gives a value less than €. But cos(7*pi/2) gives a large negative value which is not less than €.
Anshu
On Thu, 16 Jan, 2020, 11:29 PM John Maddock via Boost, < boost@lists.boost.org> wrote:
On 16/01/2020 15:08, anshu khare via Boost wrote:
cos(3*pi(cpp_bin_float_50>()/2)) does not give correct value.
What do you call "correct"? If you're expecting an exact 0 result,
then
you're going to be disappointed - likewise with double which also does not yield an exact 0 in your test case (at least on msvc).
John.
Only cos(pi(cpp_bin_float_50>()/2)) gives correct value. All odd multiples of cos(pi/2) do not give correct value.
The issue with sin() as well.
Anshu
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
On 17/01/2020 01:52, anshu khare via Boost wrote:
On running cos(3*pi/2) , cos(5*pi/2) , cos(7*pi/2) , cos(9*pi/2) all give the same answer, which is less than epsilon except cos(7*pi/2) which gives a highly negative value.
Not seeing it, I'm running: for (unsigned i = 3; i < 20; i += 2) { std::cout << std::setw(20) << i << std::setw(20) << ceil(fabs(cos(i * boost::math::constants::half_piboost::multiprecision::cpp_bin_float_50()) / std::numeric_limitsboost::multiprecision::cpp_bin_float_50::epsilon())) << std::endl; } Which gives: N abs error / epsilon 3 2 5 2 7 2 9 2 11 6 13 10 15 10 17 6 19 6 And if I switch to testing type double I see: 3 1 5 2 7 2 9 3 11 12 13 5 15 13 17 4 19 14 Best, John.
I ran the following code :
#include <iostream>
using namespace std;
#include
On 17/01/2020 01:52, anshu khare via Boost wrote:
On running cos(3*pi/2) , cos(5*pi/2) , cos(7*pi/2) , cos(9*pi/2) all give the same answer, which is less than epsilon except cos(7*pi/2) which gives a highly negative value.
Not seeing it, I'm running:
for (unsigned i = 3; i < 20; i += 2) { std::cout << std::setw(20) << i << std::setw(20) << ceil(fabs(cos(i * boost::math::constants::half_piboost::multiprecision::cpp_bin_float_50())
/ std::numeric_limitsboost::multiprecision::cpp_bin_float_50::epsilon())) << std::endl; }
Which gives:
N abs error / epsilon
3 2 5 2 7 2 9 2 11 6 13 10 15 10 17 6 19 6
And if I switch to testing type double I see:
3 1 5 2 7 2 9 3 11 12 13 5 15 13 17 4 19 14
Best, John.
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
On Fri, Jan 17, 2020 at 1:36 PM anshu khare via Boost
#include <iostream> using namespace std; #include
using boost::math::constants::pi; using boost::multiprecision::cpp_bin_float_50; int main() { cout << cos(3 * pi
/2) << endl; cout << cos(5 * pi /2) << endl; cout << cos(7 * pi /2) << endl; cout << cos(9 * pi /2) << endl; return 0; } Output is as follows:
1.06911e - 50 1.06911e - 50 -1.06911e - 50 1.06911e - 50
I'm not much of a math person, but what's a "highly negative value" to you? PI/2 is 90 degrees, and the cosine of odd multiples of 90 degrees is zero (0). And you're getting values very very close to zero, on one side of it or the other, due to some numerical error/rounding I guess. Note the fabs() is John's code example. Whether the error delta is + or - doesn't matter, it's still within 2 epsilon, and "OK" I guess. All seems "normal" here... --DD
participants (4)
-
anshu khare
-
Damian Vicino
-
Dominique Devienne
-
John Maddock