Galaxy Type
fixed is a 32-bit fixed (as opposed to floating point) number where 19 bits are available in the integer portion, 12 bits are available in the fractional portion and 1 bit is giving the sign. In the Galaxy Editor GUI fixed is referred to as a real.
- (231 - 1) / 4096 = 524287.999755859375 is the greatest
fixednumber. - -(231 - 1) / 4096 = -524287.999755859375 is the least
fixednumber. - 2-12 = 1 / 4096 = 0.000244140625, is the smallest non-zero
fixednumber.
fixed f = 1.0; f = f / 4096.0; f = f * 4096.0; // f == 1.0
Note There is a bug when using /= and *=
fixed f; f = 1; f *= 2; // f = 0.0004882812 f = 1; f /= 2; // f = 2048 f = 1; f /= 4; // f = 1024
Game File Type
- fixed32
- Sign: 1 bit
- Integer part: 19 bits (524 288)
- Decimal part: 12 bits (4096)
- fixed16
- Sign: 1 bit
- Integer part: 5 bits (16)
- Decimal part: 11 bits (2048)
- fixed8
- Unsigned
- Integer part: 0 bit
- Decimal part: 8 bits (256)
- 2 comments
- 2 comments
- Reply
- #2
vjeux Wed, 10 Mar 2010 13:02:40Here is a useful function: FixedToString
- Reply
- #1
vjeux Wed, 10 Mar 2010 08:14:33In order to know how many bits are associated to the integer and decimal part here is a handy function:
To get the decimal bound, you just test if
(f / 2n) * 2n = fand the integer bound is based on int(fixed: 2n) == int: 2n