Re: Floating-point bit hacking: iterated nextafter() without loop?
From: Eric Sosman (eric.sosman_at_sun.com)
Date: 10/18/04
- Next message: Keith Thompson: "Re: ...malloc ...from Rome :-)"
- Previous message: Keith Thompson: "Re: c equivalence of const_cast?"
- In reply to: Daniel Vallstrom: "Floating-point bit hacking: iterated nextafter() without loop?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 18 Oct 2004 11:43:30 -0400
Daniel Vallstrom wrote:
> I am having trouble with floating point addition because of the limited
> accuracy of floating types. Consider e.g. x0 += f(n) where x0 and f are
> of some floating type. Sometimes x0 is much larger than f(n) so that
> x0 + f(n) == x0. For example, x0 could be 2**300*(1.1234...) while f(n)
> is 2**100*(1.4256...). If x0 + f(n) == x0 I still sometimes want the
> addition of f(n) to x0 to have some effect on x0. A good solution seems
> to be to update x0 to the nth value greater than x0. Something
> equivalent to this:
>
> for ( ; n != 0; n-- )
> {
> x0 = nextafter( x0, DBL_MAX );
> }
> [...]
Look up "Kahan's summation formula."
-- Eric.Sosman@sun.com
- Next message: Keith Thompson: "Re: ...malloc ...from Rome :-)"
- Previous message: Keith Thompson: "Re: c equivalence of const_cast?"
- In reply to: Daniel Vallstrom: "Floating-point bit hacking: iterated nextafter() without loop?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]