I don't think that you should have to specify the amount of bits the type takes up. We can calculate that.
It would be really nice if we have the ability to create custom types (or type aliases) such that we could allow typing to be used by end users more directly, e.g. ray := decimal(places=27) for Maker codebase.
Note: 38 decimal places is the most possible that can fit in 128 bits (corresponding to fixed255x38)
List of decimals:
fixed132x1fixed135x2fixed138x3fixed142x4fixed145x5fixed148x6fixed152x7fixed155x8fixed158x9fixed162x10fixed165x11fixed168x12fixed172x13fixed175x14fixed178x15fixed182x16fixed185x17fixed188x18fixed192x19fixed195x20fixed198x21fixed202x22fixed205x23fixed208x24fixed212x25fixed215x26fixed218x27fixed222x28fixed225x29fixed228x30fixed231x31 (NOTE: doesn't fit pattern)fixed235x32fixed238x33fixed241x34 (NOTE: doesn't fit pattern)fixed245x35fixed248x36fixed251x37 (NOTE: doesn't fit pattern)fixed255x38Meeting notes: Pamp it
Was thinking about this some more today. It could be something like the following:
Decimal type, which is a fixed point type that is allowed to be any width decimal (using fixed<M>x<N> notation) as long as the calculations align at "endpoints" (internal type conversions or ABI boundaries)Decimal takes an argument (e.g. Decimal(fixed168x10)) which defines the "required" shape of the Decimal type at that interface and pins that boundary to that particular ABI typeDecimal and uses fixed<M>x<N> notation to denote that interface type. This can be overriden using the same trick for interface definitions e.g. def myCall(val: Decimal(fixed168x10)) to pin to a particular type (useful for ERCs)This design would be strictly better than doing uint256 math all over, with implicit assumptions about precision loss, and occasionally watching contract call failures from using SafeMath without due consideration to these scenarios. The compiler can also produce suggestions for the min/max size particular values can be at conversion boundary points in order to ensure correct operation of the algorithm.
Most helpful comment
Meeting notes: Pamp it