Re: QC RoundTo

From: John Herbster (herb-sci1_AT_sbcglobal.net)
Date: 06/15/04


Date: Tue, 15 Jun 2004 13:31:49 -0500


"Avatar Zondertau" <avatarzondertau@hotmail.com> wrote
> ...
> Therefore the call
> RoundTo(1.23456789012345e38, 37) = 1.2e38
> makes sense. In fact i think it's strange the range for RoundTo is
> limited.

Avatar, Dennis, et. al,
I think that you may appreciate the accuracy of some rounding
functions on the above type of problem as shown below.
Regards, JohnH

Where
  var a,r,d,e: extended; digits: integer;
and
  RoundDblTo and RoundExtTo are from the RoundToXReplacement_3c.pas
patched to allow a Digits value of > 27.

When you do
  a := 1.23456789012345e38; digits := 37;
  r := RoundTo (a,digits);
  d := RoundDblTo(a,digits);
  e := RoundExtTo(a,digits);
  LogFmt(' a=%s',[ExactFloatToStrEx(a)]);
  LogFmt(' r=%s',[ExactFloatToStrEx(r)]);
  LogFmt(' d=%s',[ExactFloatToStrEx(d)]);
  LogFmt(' e=%s',[ExactFloatToStrEx(e)]);
you get
  a=+ 1234 56789 01234 50000 02623 05589 29788 60032
  r=+ 1199 99999 99999 99897 42785 41555 58084 93568
  d=+ 1200 00000 00000 00000 08398 49257 51739 67872
  e=+ 1200 00000 00000 00000 08398 49257 51739 67872

With
  a := 1.23456789012345e27; digits := 26;
we get
digits=26
  a=+ 123 45678 90123 44999 99739 41248
  r=+ 120 00000 00000 00012 58962 28864
  d=+ 120 00000 00000 00000 00000 00000
  e=+ 120 00000 00000 00000 00000 00000

With
  a := 1.23456789012345e23; digits := 22;
we get
  a=+ 1234 56789 01234 50000 01536
  r=+ 1200 00000 00000 00000 00000
  d=+ 1200 00000 00000 00000 00000
  e=+ 1200 00000 00000 00000 00000

---


Relevant Pages

  • Re: FastCode RoundToEx
    ... RoundTo and RoundToEx is supposed to return 5 if called with ... Dennis, whatever you say, you don't seem to ... If you use FloatToStr or Writeln or any other Extended-to-text ... conversion, the conversion will lose some of the insignificant bits, ...
    (borland.public.delphi.language.basm)
  • Re: Fastcode RoundTo B&V 0.1
    ... For Dennis and other programmers interested in rounding, ... This is yet another version of routines for replacing Math ... unit's RoundTo() and SimpleRoundTo function. ... comment in QC report #8070. ...
    (borland.public.delphi.language.basm)