Is it ok to use your custom interger standard in production?

Hi guys, during the development of Swaylend I developed my custom I64 number standard because at that time I had problems with this standard from sway libs

It works like this: we have a struct I64 with value that represents absolute value and negative that represents a sign and batch of functions and operators

I studied how I64 works from sway libs, it takes the number 922333372036854775808u64 which is 2^64 / 2 for zero, and turns out and what is less than it is the negative part of it

I think in terms of implementation this approach is more correct, but it imposes a limitation:
we have a positive part of the I64 number commensurate with the u32 dimension and in some places I am stuck with arithmetic overflow, To avoid this I will have to use the I128 standard, which is created from u128, which is created from 2x u64 and I get my code clogged with a bunch of numeric transformations, which significantly increases code complexity

Can you please tell me what the right thing to do is?
I also found this library in swaylibs.

It looks like it might help me somehow, but I don’t understand how to work with it yet? Is this an implementation of what I was trying to visualize and can I replace my I64 with IFP64?

Hi there!
Tough question here.

Not sure if I can provide a specific-compiler optimized answer.

I’ll escalate this.
Thanks for sharing.

1 Like

hi, is there any updates?

Hi there!

  1. Please consider that our library have not been audited, only tested for us.

  2. It is up to you to use your own implementation.

  3. Not sure if ufp64.sw is the right choice, since it seems that you are trying to work with integers.

  4. If you want to use FuelLab’s library, you should scale up to 128 to avoid potential overflow.

Also, we might check internally if splitting the range into two is the canonical implementation, otherwise it would require some refactor on our side.

Let me know if this works for you :palm_tree: