Recent

Author Topic: "extended" real type precision  (Read 5621 times)

Pi

  • Jr. Member
  • **
  • Posts: 75
"extended" real type precision
« on: February 01, 2012, 11:46:47 pm »
According to this page http://wiki.lazarus.freepascal.org/Variables_and_Data_Types
the "extended" real type has 19-20 significant digits, but in my function it seems to be less:

eg.
procedure TForm1.Button3Click(Sender: TObject);
var the_nr: extended;
begin
  the_nr:= (1000/1001);
  showmessage(floattostr(the_nr));
end;   

running the above function shows "0.99900099900099"
if "extended" has 19-20 significant digits, shouldn't there be at least another 9 on the end?
eg. 0.999000999000999 or 0.999000999000999001 ?

Is it something to do with using floattostr - does that only work up to 15-16 significant digits because it can only use up to "double" instead of "extended"?  Should I be using something other than floattostr to convert an extended to a string keeping all 19-20 significant digits (is there a function that does or would I need to write one?)?

edit: just found it it is the floattostr function that is causing the reduced precision as I've now half-written a (not very good) function to convert an extended to string.  So I wondered if there is a better/standard way to convert an extended to string without losing precision?
« Last Edit: February 02, 2012, 01:03:16 am by Pi »
Lazarus version 0.9.30.4 + Lazarus 32 bit 1.2.6

photor

  • Jr. Member
  • **
  • Posts: 80
Re: "extended" real type precision
« Reply #1 on: February 09, 2025, 04:29:24 am »
The Extended type is suppressed on Win64 platforms.

LV

  • Full Member
  • ***
  • Posts: 239
Re: "extended" real type precision
« Reply #2 on: February 09, 2025, 06:48:44 am »
Free Pascal suppresses the Extended floating-point type on the Win64 platform because Microsoft’s 64-bit ABI (Application Binary Interface) for Windows does not support the 80-bit floating-point type (which Extended represents on 32-bit x86 platforms).

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3.   a, b: Extended;
  4.   s: string;
  5. begin
  6.   a := (1000/1001);
  7.   b := 0.123456789012345678;
  8.   s := FloatToStrF(a, ffGeneral, 18, 0) +
  9.        #13#10 +
  10.        FloatToStrF(b, ffGeneral, 18, 0);
  11.   memo1.Clear;
  12.   memo1.Lines.Add(s);
  13. end;
  14.  

output win32:
Code: Text  [Select][+][-]
  1. 0.999000999000999
  2. 0.12345678901234568
  3.  


output win64:
Code: Text  [Select][+][-]
  1. 0.999000999000999
  2. 0.123456789012346
  3.  

Workarounds: If you need more precision, you can use libraries (maybe GNU MPFR Library, AlgLib, Lmath, ...).

 

TinyPortal © 2005-2018