Recent

Author Topic: Calculations with Many Digits (>30)  (Read 1359 times)

Elap

  • Jr. Member
  • **
  • Posts: 54
Calculations with Many Digits (>30)
« on: June 26, 2019, 07:50:02 pm »
Is there a wonderful unit which does arithmetic to oodles of significant digits?

rvk

  • Hero Member
  • *****
  • Posts: 4329

Elap

  • Jr. Member
  • **
  • Posts: 54
Re: Calculations with Many Digits (>30)
« Reply #2 on: June 26, 2019, 07:59:56 pm »
Many thanks.

engkin

  • Hero Member
  • *****
  • Posts: 2513
Re: Calculations with Many Digits (>30)
« Reply #3 on: June 27, 2019, 05:24:41 am »
You might want to consider unit FmtBCD if you use trunk, or if you download it from here to overcome this bug.

Here is an example:
Code: Pascal  [Select][+][-]
  1. program Project1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   FmtBCD_bug0033795;
  7.  
  8. var
  9.   a,b,c:TBCD;
  10.   s: FmtBCDStringtype;
  11. begin
  12.   a := 2;
  13.   b := 3;
  14.   c := a/b;
  15.   s := BCDToStr(c);
  16.   WriteLn('Length: ',Length(s));
  17.   WriteLn('Result: ',s);
  18.   WriteLn;
  19. end.

Its output:
Quote
Length: 65
Result: 0.666666666666666666666666666666666666666666666666666666666666667

Or:
Code: Pascal  [Select][+][-]
  1.   a := StrToBCD('1234567890123456789012345678901234567890');
  2.   b := StrToBCD('1000000000000000000000000000000');
  3.   c := a/b;
  4.   s := BCDToStr(c);
  5.   WriteLn(Length(s));
  6.   WriteLn(s);

Gives:
Quote
Length: 40
Result: 1234567890.12345678901234567890123456789

SymbolicFrank

  • Hero Member
  • *****
  • Posts: 639
Re: Calculations with Many Digits (>30)
« Reply #4 on: June 27, 2019, 10:00:45 pm »
Interesting. I didn't know this existed. I'm going to test this.

srvaldez

  • New member
  • *
  • Posts: 5
Re: Calculations with Many Digits (>30)
« Reply #5 on: June 28, 2019, 12:20:12 pm »
the link by engkin did not work for me but this link works https://svn.freepascal.org/svn/fpc/trunk/packages/rtl-objpas/src/inc/

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8795
  • FPC developer.
Re: Calculations with Many Digits (>30)
« Reply #6 on: June 28, 2019, 12:55:21 pm »
Seems array [0..31] of byte so 64 digits.

 

TinyPortal © 2005-2018