Tuesday, November 30, 2021

Re: odd bc -l output

On Nov 30 08:38:27, pjp@delphinusdns.org wrote:
> In fact it's not just bc -l, but also when I calculate the following in C
> (linked with -lm)
>
> C = (180.0 - A) - B;
> a = (double)(c / sin(C)) * sin(A);
> b = (double)(c / sin(C)) * sin(B);
>
> Some may recognize this as parts of the Law of Sines.
>
> pjp@neptune$ bc -l
> (9 / s(70)) * s(76)
> 6.58357679385302895866
>
> When I do it with xcalc I get the correct 9.2931043.

Look at /usr/share/misc/bc.library to see what bc's s(x) really is.
Then look at lib/libm/ to see what sin() and friends really are.
(Yes, a Taylor polynom around zero; almost.)

It is known that the values of goniometric functions can get way off:
sin() at multiples of pi is nonzero, etc.

For extra laughs, read this article
https://randomascii.wordpress.com/2014/10/09/intel-underestimates-error-bounds-by-1-3-quintillion/
about how Intel tried to have fsin() in their instruction set.

Jan

No comments:

Post a Comment