How do the bignum blocks work. they are absolutely filled with bugs!

please only make one topic for one thing. If you want to change categories, don't create a new topic, just edit the topic title.

I want to know how the blocks work.

Just read the source code.

That's not a helpful answer, not for this user.

Do you mean how to use them, or do you mean how are they implemented?

The fundamental idea comes from Scheme, god's programming language, which introduced to computer science the position that if you're going to claim to support numbers, you should support all the numbers that exist, not just the ones that are built into computer hardware. When people talk about "the Scheme numeric tower," they mean integers, rational numbers, real numbers, and complex numbers. Also, the idea that programming languages should not tell their users mathematical absurdities such as that 3.0 isn't an integer. Of course it's an integer! What it isn't, is an *exact representation.* So, in Scheme, *any* number can be declared to be exact or inexact, no matter where in the tower it is. Scheme was invented by Gerald Jay Sussman and Guy Steele.

The Javascript implementation of the Scheme numeric tower that we use was written by Matthew Crumley and John Tobey; see GitHub - jtobey/javascript-bignum: Scheme arithmetic library for JavaScript. (Other people have developed other implementations too.)

The interfacing of their library with Snap*!* was done by Dylan Servilla, @djdolphin. (Now that he's over 18 I'm allowed to tell you his actual name.) Dylan's many contributions to Snap*!* also include taking over Kartik Chandra's *Snapinator* program and updating it for Scratch 3.0 projects.

As I mentioned in one of the four thousand redundant threads you've started on this topic, the library works fine on its own terms, but doesn't handle every possible user error smoothly; one of the goals was to keep its modifications to Snap*!* to a minimum.

So. How to use bignums: Just turn on the feature and do arithmetic and it just works. Of course you need to understand the underlying mathematics; for example, if you don't know about complex numbers you're not going to use them effectively, and I'm not going to try to teach you Algebra II.

How they're implemented: Real numbers just use the computer's floating-point hardware. There are mathematical reasons we can't represent every possible real number in a computer; by *mathematical* reasons I mean that they're not fixable by doing better computer programming. The other numeric types (including infinite precision integers) are implemented in software, as abstract data types. A bignum (which is a nickname for infinite precision integers) is essentially a list of digits; an exact rational is a pair of bignums for numerator and denominator; a complex number is a pair of real numbers (not necessarily floating point! 3 is a real number, just as 3.0 is an integer) for real part and imaginary part.

If you do read the code in the library, the incomprehensible part at the beginning just loads the underlying Javascript libraries, and the rest replaces each arithmetic function in Javascript with a call to the corresponding function in the Scheme-tower library.

I'm not sure you'll find this a satisfactory answer, but if you *really* want to understand how it works, I suggest you start by implementing exact rational numbers in plain Snap*!*. So, for example, you'd represent ¾ as (LIST *RAT* 3 4) where that first thing is a type tag so you know the thing you're looking at is one rational number rather than a list of integers. And you'd write a version of each function that tests its inputs to see which kind of number they are (built-in number or exact rational) and does the right thing for each type.

Do you mean not good enough as in not detailed enough for the OP to understand, or not good enough as in not being the same level of quality that my posts usually are?

I mean I'm guessing that if this user reads the code they will come away unenlightened.

I have no idea how the JS works.

yes, sort of.

Not exactly. It replaces only Snap! arithmetic operations. But new functions do not return numbers anymore but JS Objects specific to that library like BigInteger, Fraction...

Some functions are modified to accept those objects,

Evaluate

ChangeVar

,and primitive for operation

sum, difference, product, quotient, power, modulus, random, <, >, =, "is identical", "fn of n".

There are other places where numbers are processed, not covered by BigNums.

Yeah, someday we should find and fix them all. (Also someday we should talk Jens into just supporting the Scheme tower natively.)

no! it should not be native, it will affect way to many things that I want to be **NORMAL**

I think that they will just have an option to toggle it on or off (as to not break older projects)

If we ever do it at all, it'll be so robust as to not break projects that work now (as opposed to ones with errors in them). There's no way Jens could be convinced otherwise. Even I would be less than totally convinced. (I think whatever problems are in the existing library come from it being a semi-awkward overlay instead of built in.)

So I'd be interested to hear what actual projects it would break.