 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Caleb Hattingh Guest
|
Posted: Fri Apr 27, 2007 4:39 pm Post subject: Find next machine-representable number (or Delphi version of |
|
|
Hi
I'm looking for a Delphi implementation of the "nextafter" function in
C (or something similar), which, given x and y (as, say, doubles),
returns a value that is the next machine-representable number after x
in the direction of y. I have one implementation of this already
(found in an fpc forum), but I'm checking to see whether anyone in the
basm group may have fiddled with something like this before. I
intend to use this to implement "out-rounding" for interval arithmetic
operations using operator overloading in the new Delphis.
Thanks
Caleb |
|
| Back to top |
|
 |
John Herbster Guest
|
Posted: Fri Apr 27, 2007 5:16 pm Post subject: Re: Find next machine-representable number (or Delphi versio |
|
|
"Caleb Hattingh" <caleb.hattingh (AT) gmail (DOT) com> wrote
| Quote: | I'm looking for a Delphi implementation of the "nextafter"
function in C (or something similar), which, given x and y
(as, say, doubles), ...
|
Caleb,
You can find and extract such code from my
IEEE Number Analyzer, the Delphi source for which is
available from
http://cc.codegear.com/Item/23631,
The number analyzer, itself allows you can type in a
decimal number and see the *exact* floating point value.
HTH, JohnH |
|
| Back to top |
|
 |
Caleb Hattingh Guest
|
Posted: Fri Apr 27, 2007 6:50 pm Post subject: Re: Find next machine-representable number (or Delphi versio |
|
|
| Quote: | You can find and extract such code from my
IEEE Number Analyzer, the Delphi source for which is
available from
http://cc.codegear.com/Item/23631,
The number analyzer, itself allows you can type in a
decimal number and see the *exact* floating point value.
|
John,
Your functions,
function SuccExtended(e: extended): extended;
function PredExtended(e: extended): extended;
function SuccDouble(d: double): double;
function PredDouble(d: double): double;
function SuccSingle(s: single): single;
function PredSingle(s: single): single;
are, I think, precisely what I was looking for.
After every interval math
operation, such as (for addition)
[a,b]+[c,d] = [a+c,b+d]
I'll be using instead (for double precision)
[a,b]+[c,d] = [PredDouble(a+c),SuccDouble(b+d]]
This should mean that my result interval always contains the true result,
right?
Put it another way, if I create an interval from a given double, e.g.
MyInterval.SetDoubleValue(0.1)
(Where MyInterval is one of the new operator-overloaded records),
then behind the scenes I do
MyInterval.LeftBound = PredDouble(0.1);
MyInterval.RightBound = SuccDouble(0.1);
Then I can be sure that my interval captures the true value? Using your
tool, it
certainly appears to be the case when I test several different numbers
using the TUpDown
control, and I've looked at the code for these functions, but it will take
me a little
more time to become familiar with what is happening.
Many thanks
Caleb |
|
| Back to top |
|
 |
John Herbster Guest
|
Posted: Fri Apr 27, 2007 10:12 pm Post subject: Re: Find next machine-representable number (or Delphi versio |
|
|
"Caleb Hattingh" <caleb.hattingh (AT) no (DOT) spam.gmail.com> wrote
| Quote: | You can find and extract such code from my
http://cc.codegear.com/Item/23631,
Your functions,
function SuccExtended(e: extended): extended;
function PredExtended(e: extended): extended;
function SuccDouble(d: double): double;
function PredDouble(d: double): double;
function SuccSingle(s: single): single;
function PredSingle(s: single): single;
are, I think, precisely what I was looking for. ...
Many thanks
|
Caleb, I am glad that you may be able to make some
use of them. They have been tested, but I think not
exhaustively. If you find a problem, please let me know.
Yours, JohnH |
|
| Back to top |
|
 |
Nils Haeck Guest
|
Posted: Tue May 08, 2007 7:31 pm Post subject: Re: Find next machine-representable number (or Delphi versio |
|
|
Wouldn't it be simpler to use fixed point arithmetic for this?
Nils |
|
| Back to top |
|
 |
Caleb Hattingh Guest
|
Posted: Thu May 10, 2007 5:58 pm Post subject: Re: Find next machine-representable number (or Delphi versio |
|
|
| Quote: | Wouldn't it be simpler to use fixed point arithmetic for this?
|
Without John's help: probably. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|