Contract with Fixed Point and non-Fixed Point ints #43
-
How to approach a contract that has some uint256 member variables as fixed point (via PRBMathUD60x18) and some other variables that non-fixed point uint256 integers (via, for example, SafeMath)? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Update for PRBMath v3.0.0: Type safety is now offered via user defined value types |
Beta Was this translation helpful? Give feedback.
First way is to use the PRBMathSD59x18Typed.sol and PRBMathUD60x18Typed.sol flavours of PRBMath.A second way, if you intend to use the vanilla flavours of the library, is to group the fixed-point types within structs, so that I know that if I ever use that struct, all of its containing integers are fixed-point numbers. E.g. here.A third way, mentioned by @definim in #29, is to use a different nomenclature for the fixed-point variables. E.g. he used Hungarian notation.Update for PRBMath v3.0.0:
Type safety is now offered via user defined value types
SD59x18
andUD60x18
. You differentiate fixed-point from non-fixed-point types by simply declaring your variable with the value type (in fac…