Re: problem with nan
- From: Christian Bau <christian.bau@xxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 18 Apr 2005 21:09:30 +0100
In article <gtS8e.1066718$6l.84152@pd7tw2no>,
John Smith <JSmith@xxxxxxxx> wrote:
> The exercise is to calculate the approximate area of a circle by the
> "calculus method." That is, finding the area of rectangles nearly
> filling the circle. I calculate the area of rectangles in 1/4 of the
> circle and multiply by 4 to get the total area.
>
> In the code below, if the value of nrect is used in the for loop, the
> value of area goes to "nan" in the last couple of iterations. When there
> are slightly fewer iterations than the value of nrect, the output is OK.
> This behaviour is the same for smaller values of nrect.
>
> I'm not sure I understand nan (I know it means not-a-number). It seems
> to have something to do with non-representable numbers or domain/range
> errors but reading the relavent section in Harbison & Steele didn't
> entirely enlighten me. Can someone explain nan and its relation to the
> problem with this code?
Every floating point operation will give you a result that is quite
close to the mathematical correct result. If you use "1.0 / 10.0" you
will get a number close to one tenth. It might be a bit larger, or a bit
smaller.
If you add up 1.0 / 1000.0 one thousand times, then you get a result
that is relatively close to 1.0. It might be a bit smaller, it might be
a bit larger.
What is asin (x) if x is a tiny bit larger than 1.0?
.
- References:
- problem with nan
- From: John Smith
- problem with nan
- Prev by Date: Re: printf statement not executed
- Next by Date: Re: Certification in C/C++
- Previous by thread: Re: problem with nan
- Next by thread: Re: ICS has acquired UIMX
- Index(es):
Relevant Pages
|
Loading