Re: why system providing routies will provide different result in C++ and Fortran
- From: "andy2O" <andy2O@xxxxxxxxxxx>
- Date: 14 Sep 2005 15:05:20 -0700
Ian Chivers wrote:
> my main occupation is teaching programming
> to people with little or no numeric background.
>
> the mathematical value of the cosine 90 degrees is 0 and
> the tangent of 90 degrees is infinity.
>
> to the complete beginner to programming the actual
> values returned don't make much sense.
>
> i don't claim that the values are wrong, but that they
> are not at all obvious to the beginner.
>
OK, even good trig functions can only return closest floating point
approximations - and I'm all for teaching it to all who will listen...
But on reading the sample code, my first reaction was that the much
bigger and more straightforward error would be if someone assumed that
when angles==90, that the (rational) floating point value of r could
ever be identical to pi/2 (an irrational number)....
Clearly r==pi/2 is impossible for floating point r, so a (hypothetical)
perfect precision cos function *should never* return cos(r)==0 for a
floating point value of r. Infact if it did return cos(r)==0, wouldn't
that be certain evidence that the cos function in question was not of
perfect precision...
(I think best go off to reread "What every computer scientist should
know about floating point arithmetic" myself...)
Yours,
Andy.
> "Brooks Moses" <bmoses-nospam@xxxxxxxxxxxxxxxxxx> wrote in message
> news:4328831B.1050902@xxxxxxxxxxxxxxxxxxxxx
> > Ian Chivers wrote:
> >> Here is a test program
> > [...]
> >> r=pi*angles(i)/180
> >> print *,angles(i),' ',sin(r),' ',cos(r),' ',tan(r)
> > [...]
> >> 61 0.8746197 0.4848096 1.804048
> >> 89 0.9998477 1.7452383E-02 57.29004
> >> 90 1.000000 -4.3711388E-08 -2.2877332E+07
> >> 91 0.9998477 -1.7452471E-02 -57.28975
> >>
> >> note the sign at 90 degrees of the cos and tan.
> >
> > Yes. What's wrong with it?
> >
> > Clearly, r is an approximation to pi/4 in any limited-precision
> > calculation, and thus these values are values for some angle that's nearly
> > but not exactly 90 degrees. Thus, I can't see any reason to claim that
> > either sign would be wrong here, unless you have some specific claim about
> > what side of pi/4 r happens to lie on.
> >
> > - Brooks
> >
> >
> > --
> > The "bmoses-nospam" address is valid; no unmunging needed.
.
- Follow-Ups:
- Re: why system providing routies will provide different result in C++ and Fortran
- From: John Harper
- Re: why system providing routies will provide different result in C++ and Fortran
- From: glen herrmannsfeldt
- Re: why system providing routies will provide different result in C++ and Fortran
- References:
- why system providing routies will provide different result in C++ and Fortran
- From: Qian Xin
- Re: why system providing routies will provide different result in C++ and Fortran
- From: Ian Chivers
- Re: why system providing routies will provide different result in C++ and Fortran
- From: Rich Townsend
- Re: why system providing routies will provide different result in C++ and Fortran
- From: Ian Chivers
- Re: why system providing routies will provide different result in C++ and Fortran
- From: Brooks Moses
- Re: why system providing routies will provide different result in C++ and Fortran
- From: Ian Chivers
- why system providing routies will provide different result in C++ and Fortran
- Prev by Date: Re: why system providing routies will provide different result in C++ and Fortran
- Next by Date: Re: PL/I Cant create a Upper case function
- Previous by thread: Re: why system providing routies will provide different result in C++ and Fortran
- Next by thread: Re: why system providing routies will provide different result in C++ and Fortran
- Index(es):
Relevant Pages
|
Loading