Discussion:
bignum math library
Geoff Canyon via use-livecode
2018-11-18 18:28:30 UTC
Permalink
I've created bignum libraries in the past, but never organized it or did
all four operators. So I started with earlier versions of some of the
functions, optimized, corrected, and extended, and here it is:
https://github.com/gcanyon/bignum

It includes functions for addition, subtraction, multiplication, division,
and comparison/equals. All functions handle any length of argument. Most
have options that handle signed arguments. The functions are optimized for
things like different-length arguments.

Some performance benchmarks on my five-year-old laptop:

Add two 10,000 digit numbers: 0.005 seconds.
Add two 10,000 digit numbers: 0.004 seconds.
Multiply two 10,000 digit numbers: 3.1 seconds.
Divide a 10,000 digit number by a 5,000 digit number: 9.4 seconds -- needs
some optimization.

For division in particular, I wrote a faster algorithm that is included,
but there is a bug in the final steps that I haven't figured out yet.
bigDivFlawed is about 40% faster than bigDiv, but can bork the last few
digits of the quotient. Included in case anyone sees the logic error.

If anyone has any suggestions, let me know here, or file bug reports on
github, or code and submit a pull request.

A list of the functions included:


function bigAdd -- returns the sum
function bigAddSigned -- handles positive and negative arguments
function bigSubtract -- returns the difference
function bigSubtractSigned -- handles positive and negative arguments
function bigTimes -- returns the product
function bigTimesSigned -- handles positive and negative arguments
function bigDiv -- returns (the integer quotient),(the remainder)
function bigDivSigned -- handles positive and negative arguments
function bigishDiv -- Handles any length dividend; divisor must be a valid
LC number (< 16 digits)
function bigDivFlawed -- About 40% faster than bigDiv, but can bork the
last few digits of the quotient. Included in case anyone sees the logic
error.
function bigCompare -- Applies >,<,=,<=,>= to any length arguments
function stripLeadingZeros -- returns any string without whatever leading
zeros it contains
Tom Glod via use-livecode
2018-11-18 22:20:52 UTC
Permalink
very impressed ..thank you.

On Sun, Nov 18, 2018 at 1:29 PM Geoff Canyon via use-livecode <
Post by Geoff Canyon via use-livecode
I've created bignum libraries in the past, but never organized it or did
all four operators. So I started with earlier versions of some of the
https://github.com/gcanyon/bignum
It includes functions for addition, subtraction, multiplication, division,
and comparison/equals. All functions handle any length of argument. Most
have options that handle signed arguments. The functions are optimized for
things like different-length arguments.
Add two 10,000 digit numbers: 0.005 seconds.
Add two 10,000 digit numbers: 0.004 seconds.
Multiply two 10,000 digit numbers: 3.1 seconds.
Divide a 10,000 digit number by a 5,000 digit number: 9.4 seconds -- needs
some optimization.
For division in particular, I wrote a faster algorithm that is included,
but there is a bug in the final steps that I haven't figured out yet.
bigDivFlawed is about 40% faster than bigDiv, but can bork the last few
digits of the quotient. Included in case anyone sees the logic error.
If anyone has any suggestions, let me know here, or file bug reports on
github, or code and submit a pull request.
function bigAdd -- returns the sum
function bigAddSigned -- handles positive and negative arguments
function bigSubtract -- returns the difference
function bigSubtractSigned -- handles positive and negative arguments
function bigTimes -- returns the product
function bigTimesSigned -- handles positive and negative arguments
function bigDiv -- returns (the integer quotient),(the remainder)
function bigDivSigned -- handles positive and negative arguments
function bigishDiv -- Handles any length dividend; divisor must be a valid
LC number (< 16 digits)
function bigDivFlawed -- About 40% faster than bigDiv, but can bork the
last few digits of the quotient. Included in case anyone sees the logic
error.
function bigCompare -- Applies >,<,=,<=,>= to any length arguments
function stripLeadingZeros -- returns any string without whatever leading
zeros it contains
_______________________________________________
use-livecode mailing list
Please visit this url to subscribe, unsubscribe and manage your
http://lists.runrev.com/mailman/listinfo/use-livecode
hh via use-livecode
2018-11-19 07:14:54 UTC
Permalink
On LC Global (Nov 2018, Monthly report) Kevin and Ali announced among
others "Decimal Number Implementation", see my screenshot
http://forums.livecode.com/viewtopic.php?f=76&t=31797

This is probably close to an arbitrary-precision Decimal type,
I know the javascript version:
https://github.com/MikeMcl/decimal.js/

Perhaps it is possible to have "synergetic effects" by joining your work?
Geoff Canyon via use-livecode
2018-11-19 20:32:50 UTC
Permalink
There are libraries for this stuff in C. I'm sure if they incorporate
something in the engine my stuff would be entirely unnecessary. Anything in
C is going to *far* outclass/speed anything I've done in script.

On Sun, Nov 18, 2018 at 11:15 PM hh via use-livecode <
Post by hh via use-livecode
On LC Global (Nov 2018, Monthly report) Kevin and Ali announced among
others "Decimal Number Implementation", see my screenshot
http://forums.livecode.com/viewtopic.php?f=76&t=31797
This is probably close to an arbitrary-precision Decimal type,
https://github.com/MikeMcl/decimal.js/
Perhaps it is possible to have "synergetic effects" by joining your work?
_______________________________________________
use-livecode mailing list
Please visit this url to subscribe, unsubscribe and manage your
http://lists.runrev.com/mailman/listinfo/use-livecode
hh via use-livecode
2018-11-19 23:02:12 UTC
Permalink
Here's a scenario that makes your scripts nevertheless valuable.

If they implement "Decimal number" for LC Builder, what I hope,
because the numbers implementation in LCB is rather uncomplete.
Geoff Canyon via use-livecode
2018-11-19 23:26:04 UTC
Permalink
Well, the code is theirs to use if it's useful. We'll see.

On Mon, Nov 19, 2018 at 3:02 PM hh via use-livecode <
Post by hh via use-livecode
Here's a scenario that makes your scripts nevertheless valuable.
If they implement "Decimal number" for LC Builder, what I hope,
because the numbers implementation in LCB is rather uncomplete.
_______________________________________________
use-livecode mailing list
Please visit this url to subscribe, unsubscribe and manage your
http://lists.runrev.com/mailman/listinfo/use-livecode
Loading...