Thankful For Mathematics

Uhhhh I’ve made a mistake.

Each integer in the 4-integer series represents a digit in base-10,000.

Why 10,000?

Because I’m a moron, apparently.

I had asked the question of “what’s the most-distant orbital distance (in meters) that I would need to keep track of?” and came up with a really big number, so I ignorantly just counted the base-10 digits of the result, and split them into equal groups of 4, rounding up, which means each group is 4 digits long, allowing it to store anything from 0 to 9,999. Hence: base-10,000.

So, uh… I sorta did this because it was natural and intuitive for me, and helped me figure out how the algorithms worked, but I failed to remember that I’m trying to make a version of BigNumber that’s easier on the interpreter.

It has now occurred to me, just now, that my chosen base forces me to use an integer division operation, every time I want to iterate through digits. I just learned a few days ago that division was really slow, and I’ve now connected the dots as to why most multi-word integers are implemented with bases built around powers of 2, because it would let me replace all division with bit-shifting, which is so much faster.

My code for the MegaRegister is really…uh…awkward, because it’s based entirely on constants and macros, to create a tightly-defined execution environment, both for speed and memory recycling. I didn’t want the CPU or interpreter to worry about execution stacks, or allocating memory for temporary variables. Of course, this isn’t the best corporate code, but corporate code probably won’t solve the BigNumber problem.

I am now beholding all this code, and realizing I gotta rewrite a lot of macros and general code to accommodate a new base value, which would allow me to ditch division, in favor of bit-shifting.

Ugh.

Like, I was literally reading what @ramstrong had explained, and was like “Oh that’s interesting, he’s using bit-shifting instead of division. In a thread where I’m lamenting about how slow division is. I wonder why that is.”

MAYBE IT’S BECAUSE HE KNOWS WHAT HE’S DOING, AND MY IMPLEMENTATION COULD BE AS FAST AND EFFICIENT AS WHAT HE OUTLINES, IF I COULD REALIZE THAT DIVISION IS SLOW, AT EVERY LEVEL OF EXECUTION.

So, uh…I got a lot more spoons to gather, and a lot of rewriting to do…

I have this weird habit of constantly chasing the hard problems.

The really big shambling mess in the room, though, is that I’m doing a lot of coding and implementation, but I need to figure out a way to do timed tests, and compare what I got so far with BigNumber. There’s a lot of work to reach a testing state, though, and there is still a possibility that this will be slower than BigNumber.

4 Likes

I’m not sure that I have fully understand your “base-10.000 math”, aside that looks like a sort of 10-bit BCD; If so, I can agree that handling the overflow between 1001 and 1023 is indeed awkward; if you want decimal math, perhaps is better use the good ol’ 4-bit BCD, or I have misunderstand something ?

Best regards from Italy,
dott. Piergiorgio.

2 Likes

If by “BCD”, you mean “binary-coded decimal”, then yes.

Basically I have 4 BCDs, and each handles 4 digits (0 to 9,999) of a massive base-10 number (0 to 9,999,999,999,999,999). All 4 BCDs work together to store a 16-digit integer in base-10.

I’m now realizing that I should have started this as 4 “digits” of 16 bits (0 to 511), thus giving me a 4-digit number in base-512 (0 to 18,446,744,073,709,551,615). That way, I can do bit-shifting between digits, and ensure they don’t get corrupted, or do unnecessary math to make it work out.

I’m essentially trying to recreate what would be an intrinsic 64-bit unsigned integer in any other language, without tossing all 64 bits to garbage collection constantly, like what BigNumber does.

Also, full disclosure: No hate to Michael J Roberts at all. BigNumber does its job well, and nobody would expect some wacko to come along and attempt an orbital mechanics game in their IF language. I fully own up to the fact that I am doing weird stuff again.

3 Likes

was. You’re no longer ignorant.

Congratulations on learning new knowledge. You’re that much a better man!

2 Likes

That’s the spirit! Thank you!! ^^

3 Likes

UPDATE: I gotta put this down. It’s not good for my sanity.

I know what I need to do, but it’ll be better as a full-rewrite in a standalone module.

But I gotta work on something easier for a bit.

2 Likes

If you’re looking for something easier, I heard there’s a comp with a low entry threshold open to virtually any topic, but that could be just a vicious dirty rumor. :thinking:

1 Like

Yeah I got an idea for a TADS horror game, so I can use the new Adv3Lite 1.6, but I don’t think it’ll be done in time for the TADS Winter Comp :upside_down_face:

There’s a vague chance I’ll have the tiniest demo complete by then, but I’m not sure…

1 Like

I don’t think it’s so much that as T3 is something like 17 years old and it’s a revision of a design that’s almost 35 years old. The first version of TADS was written at a time when you couldn’t expect that a random desktop computer would have a floating point unit at all.

2 Likes