Recent

Author Topic: Anyone interested in testing a new Big Integer library?  (Read 19746 times)

ad1mt

  • Full Member
  • ***
  • Posts: 199
    • Mark Taylor's Home Page
Re: Anyone interested in testing a new Big Integer library?
« Reply #75 on: December 20, 2023, 03:06:42 pm »
FPC isn't broken. This is by design due to how the x87-coprocessor behaves.
Here is a small program that shows the problem. To see the problem, you *must* compile this with the 32bit compiler. Everything works correctly on the 64bit compiler:
Code: Pascal  [Select][+][-]
  1. program test_single_7;
  2. uses    math;
  3. var
  4. R:single;
  5. got_exception:boolean=false;
  6. begin
  7. R:= 9**9;
  8. try
  9.   R:= R*R*R*R*R;
  10.   except
  11.     got_exception:= true;
  12.     writeln('1st exception arrived ok');
  13.   end;
  14. if (not got_exception) then writeln('1st exception failed to happen');
  15. try
  16.   R:= 9**2;
  17.   except
  18.     writeln('got 2nd exception - this is incorrect');
  19.   end;
  20. end.
This is absolutely distrastrous if you are trying to write rubust and bug-free code. This is a trivial example, but consider the consequences if the code was extremely complex. It would be a nightmare to debug. But more importantly, it would be impossible to get the logic working correctly.
Also please consider the consequences for beginner programmers, trying out Pascal for the first time. Free Pascal is the best compiler available, and problems like this will discourage those people from looking at Pascal. Do you really expect beginner programmers to know and understand the low-level complexities of Intel CPUs, in order to get their code to work correctly?
EDIT - it also appears to be a regression... code generated by the 32bit FPC v3.2.0 behaves correctly, i.e. in the above program the 1st exception arrives.

Your point that every float calculation requires an fwait is not correct.
An fwait is only required inside a try...except statement, and only at the end of the try clause of the statement, like this:
Code: Text  [Select][+][-]
  1. try
  2. float:= (9 ** 9);
  3. float:= (float * float);
  4. float:= (float ** float);
  5. <--- fwait only needs to be inserted here
  6. except writeln('exception')
  7. end;

There many, many features of the Pascal language that slow down execution a little. But that is a small price to pay for the benefits of reliable, easy to debug programs.
« Last Edit: December 22, 2023, 03:58:26 pm by ad1mt »

PascalDragon

  • Hero Member
  • *****
  • Posts: 5486
  • Compiler Developer
Re: Anyone interested in testing a new Big Integer library?
« Reply #76 on: December 21, 2023, 10:21:58 pm »
Once again with emphasis:

THIS. IS. BY. DESIGN. AND. CHOICE.

And you know what? The most recent Delphi version even completly switches off FPU exceptions by default. C and C++ code normally doesn't have them enabled either.

ad1mt

  • Full Member
  • ***
  • Posts: 199
    • Mark Taylor's Home Page
Re: Anyone interested in testing a new Big Integer library?
« Reply #77 on: December 23, 2023, 01:36:05 am »
I've just made v4.33 available. This has better exception handling if the Initialisation is called incorrectly.
I've also written better documentation.
EDIT - some minor updates to the documenation (attached).
« Last Edit: December 23, 2023, 11:54:44 am by ad1mt »

BeniBela

  • Hero Member
  • *****
  • Posts: 907
    • homepage
Re: Anyone interested in testing a new Big Integer library?
« Reply #78 on: December 24, 2023, 04:46:28 pm »
Once again with emphasis:

THIS. IS. BY. DESIGN. AND. CHOICE.

And you know what? The most recent Delphi version even completly switches off FPU exceptions by default. C and C++ code normally doesn't have them enabled either.

No exceptions are better than unreliable and inconsistent exceptions. Then it is the same behaviour on 32- and 64-bit systems


If Delphi did that, FPC needs to disable exceptions, too, for Delphi compatibility

PascalDragon

  • Hero Member
  • *****
  • Posts: 5486
  • Compiler Developer
Re: Anyone interested in testing a new Big Integer library?
« Reply #79 on: December 27, 2023, 06:46:20 pm »
If Delphi did that, FPC needs to disable exceptions, too, for Delphi compatibility

Delphi compatibility isn't the be-all-end-all when backwards compatibility is involved as well.

Thaddy

  • Hero Member
  • *****
  • Posts: 14377
  • Sensorship about opinions does not belong here.
Re: Anyone interested in testing a new Big Integer library?
« Reply #80 on: December 28, 2023, 03:03:33 pm »
@Benibella

And why do you not disable the exceptions yourself?
That is easy and frankly I found it the wrong decision for Delphi.
But since they rely more and more on LLVM I can find an excuse, albeit a lame one.
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

ad1mt

  • Full Member
  • ***
  • Posts: 199
    • Mark Taylor's Home Page
Re: Anyone interested in testing a new Big Integer library?
« Reply #81 on: January 01, 2024, 05:31:14 pm »
I've just made version 4.34 available.
It has a significantly faster division algorithm, 10-30 times faster, depending on the big integer size. I finally managed to get the Warren-Knuth algorithm working (or at least, my re-engineered version of it). It also has some other minor improvements, and updated documentation.

ad1mt

  • Full Member
  • ***
  • Posts: 199
    • Mark Taylor's Home Page
Re: Anyone interested in testing a new Big Integer library?
« Reply #82 on: January 01, 2024, 07:45:19 pm »
I've just made version 4.34 available.
If anyone has downloaded this version prior to 18:43 (5:43pm), please download again. There was a testing bug left in the code.
My test suite needs to be improved... it should have picked this up.

ad1mt

  • Full Member
  • ***
  • Posts: 199
    • Mark Taylor's Home Page
Re: Anyone interested in testing a new Big Integer library?
« Reply #83 on: January 04, 2024, 08:06:01 pm »
Completed another stage of development: compiled and tested ok on a 32bit Raspberry Pi 1B running Linux.
Not surprisingly, it ran rather slowly!

ad1mt

  • Full Member
  • ***
  • Posts: 199
    • Mark Taylor's Home Page
Re: Anyone interested in testing a new Big Integer library?
« Reply #84 on: January 12, 2024, 08:45:03 pm »
I've just made version 4.35 available.
This has big integers that resize themselves automatically.

ad1mt

  • Full Member
  • ***
  • Posts: 199
    • Mark Taylor's Home Page
Re: Anyone interested in testing a new Big Integer library?
« Reply #85 on: February 08, 2024, 04:39:13 pm »
I've just made available an update to v4.35.
It has shr & shl operators... I forgot about these!
It also has important bug fixes.

ad1mt

  • Full Member
  • ***
  • Posts: 199
    • Mark Taylor's Home Page
Re: Anyone interested in testing a new Big Integer library?
« Reply #86 on: February 28, 2024, 03:48:50 pm »
I've just made v4.37 available.
This has NOT, AND & OR functions; and bug fixes to the XOR function, to improve the way negative operands are handled.

ad1mt

  • Full Member
  • ***
  • Posts: 199
    • Mark Taylor's Home Page
Re: Anyone interested in testing a new Big Integer library?
« Reply #87 on: March 08, 2024, 01:00:26 am »
Just made an update available. This fixes some bugs in bitshift operations when range-checking is enabled with the 32-bit compiler/target.

ad1mt

  • Full Member
  • ***
  • Posts: 199
    • Mark Taylor's Home Page
Re: Anyone interested in testing a new Big Integer library?
« Reply #88 on: March 11, 2024, 06:25:04 pm »
New version... more bug fixes. When will I get to the end of this?

Bart

  • Hero Member
  • *****
  • Posts: 5290
    • Bart en Mariska's Webstek
Re: Anyone interested in testing a new Big Integer library?
« Reply #89 on: March 11, 2024, 06:41:26 pm »
New version... more bug fixes. When will I get to the end of this?
Never: there will always be bugs or feature requests  O:-)

Bart

 

TinyPortal © 2005-2018