Re: problem with nan



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?
.



Relevant Pages

  • Re: problem with nan
    ... > filling the circle. ... > 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. ... The problem here is that sinx eventually grows beyond the domain of the ...
    (comp.lang.c)
  • Re: selective plot and calculation
    ... arbitrary shape, isn't it? ... I'm not sure if it is possible to get a perfect circle hole in the plot. ... However you can still have an approximatly circle shape. ... zz= NaN; ...
    (comp.soft-sys.matlab)
  • Re: Fitting a image into a circle
    ... How can I fit a image into a circle? ... then, I plot a circle: ... After combine the two images and then apply NaN as you said, ...
    (comp.soft-sys.matlab)
  • Re: Fitting a image into a circle
    ... How can I fit a image into a circle? ... then, I plot a circle: ... radius to NaN. ...
    (comp.soft-sys.matlab)
  • problem with nan
    ... finding the area of rectangles nearly filling the circle. ... 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. ... double len, area, radius, newht; ...
    (comp.lang.c)

Loading