Kolterdyx / mcbasic

A custom scripting language for generating complex Minecraft datapacks
GNU General Public License v3.0
0 stars 0 forks source link

Decimal number arithmetic #5

Open Kolterdyx opened 3 months ago

Kolterdyx commented 3 months ago

This issue is here to discuss decimal number arithmetic (floating/fixed point numbers) implementation.

Current implementation is whacky at best. It uses fixed point numbers and it has trouble with big numbers because it has to give up digits for decimal values. Addition and subtraction work fine, but multiplication and division cause a lot of trouble since either one or both of the numbers in the operation have to be scaled up or down by 10 to the power of however many digits of precision we have, which causes even more overflow issues. The only good thing is that it's almost as efficient as integer arithmetic (because it technically IS integer arithmetic). The implementation was severely limited by the fact that commands can't return floating point values, which means I couldn't store actual float/double values in storage, and then scale them up or down when needed. This is sadly working as intended so I doubt I'll be able to fix this without a huge overhaul implementing my very own data type.

WOODEN-CHEST commented 3 months ago

I'll create a datapack implementation of the Decimal type which I previously talked about and share it.

I found some ways to optimize it and make it use fewer commands, and most commands it uses are scoreboard and execute if commands, which are rather fast according to tests I did, so it should be sufficient for datapacks.

Kolterdyx commented 3 months ago

I have also found this project, which looks really good in terms of features, but I don't like that it does everything by using an entity and applying transformations to entities. We could maybe use your implementation for fast basic operations and then use gibbsly's library for complex operations which will be heavy anyways