Skip to content

When to (un)wrap (un)signed integers #149

Closed Answered by PaulRBerg
pimhakkert asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @pimhakkert, thank you for your question.

so all my uint256 variables would be safe to work with

Actually, they weren't safe.

The goal with a fixed-point math library is to emulate decimals with simple integers - this means that non-emulated numbers should NOT be used together with emulated numbers, e.g. you should not take the logarithm of a non-emulated (non-fixed-point) uint256. Though there are exceptions, this is an important rule of thumb that can prevent nasty bugs that are otherwise hard to detect.

My question is, when do I wrap and unwrap the integers?

This is a very broad question that I cannot answer succinctly, I'm afraid. What I can do is recommend you to Solidity's bl…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@pimhakkert
Comment options

@PaulRBerg
Comment options

@pimhakkert
Comment options

Answer selected by pimhakkert
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #149 on December 16, 2022 13:35.