💾 Archived View for freeshell.de › gemlog › 2022-07-28_Whitespace__part_3.gmi captured on 2023-07-22 at 16:26:52. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2023-01-29)

-=-=-=-=-=-=-

Whitespace, part 3 ⬜⬜⬜

The only data type in Whitespace is "arbitrarily large integer" which can represent a character or a heap address or a plain old integer. It's easy to get it wrong. You want to do arithmetic on a heap value, but you forget that you have an address, not the number. You still have an integer waiting for the next instruction, but it won't be the one you wanted. Thank heaven I have a debugger.

I implemented a reverse Polish calculater, and it was pleasing to write something moderately useful. But with only integers, it was not *that* useful. Then I thought I could represnt a float as two integers, Value and Scale, which represent V×10^S. So I implemented a bunch of floating point arithmetic macros, and now I have a floating point calculator in a language that doesn't support floats.

Once I had +-×÷% I wondered about how to implement x^y. Simple enough for integer powers, but I had no idea how to work out, say 3^2.7, and it was hard to google that. Eventually I found someone who'd demonstrated a method he attributed to Euler. First, 3^2.7 = 3^2 × 3^0.7 so we've reduced part of it to multiplication. The other part is between 3^0 and 3^1, and you narrow the range iteratively until you get the answer, or get close enough. But it takes a lot of iterations, *and* it involves square roots. Well, there's also an interative method for calculating square roots. I worked on that a bit and found that it got a decent result in 4 or 5 iterations if you choose your first guess sensibly. But although I've found how to do 3^2.7 with simple arithmetic in a spreadsheet, that means that I just know what arithmetic is needed. Implementing in Whitespace is another thing altogether.

I put all this on Codeberg, but why would you want it??

#Whitespace

#programming

back to gemlog