4 ms·
Only integers? Wow. Were int pairs used to represent numbers with decimals or what?
by pfraze 6y ago
Only integers? Wow. Were int pairs used to represent numbers with decimals or what?
- timerol 6y agoTo use only integers, you generally try to express all numbers in units of the smallest quantity. So any money is in integer cents, any distance is in integer (spatial resolution size). It gets annoying with derived units: Time can be stored in integer frames, but then you'll need a rational type of some kind to properly handle velocity. Or you just round to the nearest (spatial resolution) per frame and hope the errors don't look too weird on the other side.
- salicideblock 6y agoIn signal processing on constrained domains (constrained including the lack of an FPU), the usual alternative to floating point is "fixed point" arithmethic. Basically you use the platform's native types (e.g. uint32) and decide which of the bits are for the integer part and which are for the fractional. uint32 can be interpreted as 20/12 for example. Your register went from representing "units" to representing "2^-12 increments of an unit". The ALU can do sum/comparison/subtractions transparently, but multiplications and (god forbid) divisions require shifting to return to the original representation. The choice of how to split the bits is a tradeoff between range and precision. It can vary from one routine to another. It's a pain to compose code with it. Short story: native float types are a blessing for programmer productivity and library interoperability.
- okl 6y agoThe Wikipedia page explains the operations: https://en.wikipedia.org/wiki/Q_(number_format) https://en.wikipedia.org/wiki/Q_(number_format)
- linkdd 6y agoLet's say you have two 4 bits integer to form an 8 bit decimal number: 1111.1111 is (1 + 2 + 4 + 8) + (1/2 + 1/4 + 1/8 + 1/16)
- coopierez 6y agoThe GPU made use of fixed point numbers. So you have a set number of decimal places for a number.