Recent

Author Topic: Large/Big Integer Library in pure Pascal  (Read 9233 times)

AlexTP

  • Hero Member
  • *****
  • Posts: 2401
    • UVviewsoft
Re: Large/Big Integer Library in pure Pascal
« Reply #15 on: July 19, 2022, 08:10:28 pm »
I created the GitHub repo for TForge 0.76
https://github.com/Alexey-T/TForge-Pascal

Cannot find the license in any place.

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1228
Re: Large/Big Integer Library in pure Pascal
« Reply #16 on: July 20, 2022, 03:06:56 am »
Hello,
I created the GitHub repo for TForge 0.76
https://github.com/Alexey-T/TForge-Pascal

Cannot find the license in any place.
Have a look here. it seems that the license is an Apache-2.0 License

Friendly, J.P
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

Thaddy

  • Hero Member
  • *****
  • Posts: 14364
  • Sensorship about opinions does not belong here.
Re: Large/Big Integer Library in pure Pascal
« Reply #17 on: July 20, 2022, 03:34:31 am »
Yes, I did that as well, but it wasn't that easy and I only got it partly working. Out of the box, it totally doesn't compile.
My biggest trick was to define a Delphi version when FPC is used. So fake a Delphi version. After that, I just needed to remove the scoped calls.
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: Large/Big Integer Library in pure Pascal - UPDATE
« Reply #18 on: July 20, 2022, 01:09:12 pm »
Reinvent the wheel?
It does indeed appear that I've wasted my time by re-inventing the bigint...
When I originally searched over a year ago, the best library I found was the FNX library
   https://forum.lazarus.freepascal.org/index.php/topic,48925.msg353304.html#msg353304
But it uses asembly language, so I thought it was not suitable for me, as my code had to run on 32bit Solaris SPARC CPUs.
I've just gone back and had another look at it... and the assembly code can be disabled, so that it uses only Pascal!
FNX can be downloaded from here
  https://www.ellipsa.eu/public/fnx/fnx.html
It's easy to use and fast. It's twice as fast as my code, which I had assumed was because of the assembly language, but now I realise it's fast because it's better.
It does have a limitation in that it requires a 64bit CPU, but this is unlikely to be a problem for most people.
I recommend FNX to anyone who needs a bigint library for Free Pascal, which does not use assembly language.
« Last Edit: July 20, 2022, 01:14:15 pm by ad1mt »

ad1mt

  • Full Member
  • ***
  • Posts: 199
    • Mark Taylor's Home Page
Re: Large/Big Integer Library in pure Pascal
« Reply #19 on: July 20, 2022, 01:11:10 pm »
Although I wasted my time, it was fun and very educational to re-invent the bigint!!!

af0815

  • Hero Member
  • *****
  • Posts: 1291
Re: Large/Big Integer Library in pure Pascal
« Reply #20 on: July 20, 2022, 01:15:22 pm »
Although I wasted my time, it was fun and very educational to re-invent the bigint!!!
This is full ok, sometimes the the way is the target, not the result.
regards
Andreas

srvaldez

  • New Member
  • *
  • Posts: 36
Re: Large/Big Integer Library in pure Pascal
« Reply #21 on: July 20, 2022, 04:10:38 pm »
hello ad1mt :)
there's nothing wrong with re-inventing the wheel, it's good for learning

BeniBela

  • Hero Member
  • *****
  • Posts: 906
    • homepage
Re: Large/Big Integer Library in pure Pascal
« Reply #22 on: July 20, 2022, 07:33:05 pm »
I also wrote one: https://benibela.de/sources_en.html#bigdecimalmath

Not just for integers, but also decimals like "10.3"

ad1mt

  • Full Member
  • ***
  • Posts: 199
    • Mark Taylor's Home Page
Re: Large/Big Integer Library in pure Pascal
« Reply #23 on: July 22, 2022, 01:55:43 pm »
I think the compiler should come with a basic big integer as standard, written in Pascal so it will "compile and run anywhere". it seems many people (not just myself) re-invent the big integer library.
Telling people to use GMP, is not good enough for a compiler that should "compile & run anywhere".

ad1mt

  • Full Member
  • ***
  • Posts: 199
    • Mark Taylor's Home Page
Re: Large/Big Integer Library in pure Pascal
« Reply #24 on: July 22, 2022, 02:24:59 pm »

Into the abyss:

Code: Pascal  [Select][+][-]
  1.  
  2. function qmult(aa:ansistring;bb:ansistring):ansistring;
  3.  

Hi BobDog...
I read your post, and was puzzled.
So I built & ran your code but I'm still puzzled.
Please can you explain?
Is your code actually multiplying to very large numbers inside strings?
Thanks, Mark.


BobDog

  • Sr. Member
  • ****
  • Posts: 394
Re: Large/Big Integer Library in pure Pascal
« Reply #25 on: July 22, 2022, 05:50:57 pm »

It can multiply two numbers written as strings.
It works base 10 by string indexing, it is not the fastest.
The next slowest down is pen and paper.

GMP is my favourite external big number library.
It is probably the fastest one around.
It is written in C of course, and is very portable.
These ancient languages, Pascal, C, C++, Fortran and Basic tend not to have a built in big number library, but I think Lisp does a switch over.
I think a few of the functional languages include one.
Also
Python does, but it would, wouldn't it?




Thaddy

  • Hero Member
  • *****
  • Posts: 14364
  • Sensorship about opinions does not belong here.
Re: Large/Big Integer Library in pure Pascal
« Reply #26 on: July 22, 2022, 09:27:42 pm »
Python uses a C backend for that, so that is technically not correct.
FreePascal is low level enough to do the same as C does in most if not all cases.
It is more how much effort can be put in.

Python on itself is a big wrapper around libraries written in other - real - languages.
Note I love Python and use it daily, so I am not bashing.
In fact Python does so by design.
« Last Edit: July 22, 2022, 09:36:03 pm by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

AlexTP

  • Hero Member
  • *****
  • Posts: 2401
    • UVviewsoft
Re: Large/Big Integer Library in pure Pascal
« Reply #27 on: July 26, 2022, 01:27:02 pm »
I compiled (ie 'listed', not 'compiled') all found stuff (except C lib GMP) here
https://wiki.freepascal.org/BigInteger

What did I miss?
« Last Edit: July 26, 2022, 08:46:10 pm by AlexTP »

MathMan

  • Sr. Member
  • ****
  • Posts: 325
Re: Large/Big Integer Library in pure Pascal
« Reply #28 on: July 27, 2022, 11:00:48 am »
I compiled (ie 'listed', not 'compiled') all found stuff (except C lib GMP) here
https://wiki.freepascal.org/BigInteger

What did I miss?

Thanks Alex. Over time I made contact with several more, but need to do a little research if they are still available on the web somewhere. They all date back to the 0's or mid 10's latest. Names that spring to mind immediately are 'LongMathForPascal', 'BigInt', 'HugheInt' & 'GInt' (if we still stay with pure Pascal only).

I can maybe also provide some comments on capabilities of individual packages (if this is desired), as I took a look at each of them over time.

Regards,
MathMan

SymbolicFrank

  • Hero Member
  • *****
  • Posts: 1313
Re: Large/Big Integer Library in pure Pascal
« Reply #29 on: July 27, 2022, 11:40:12 am »
I can maybe also provide some comments on capabilities of individual packages (if this is desired), as I took a look at each of them over time.

That would be appreciated.

 

TinyPortal © 2005-2018