BASEDNUM, the best numbers on Earth =================================== by drummyfish, released under CC0 1.0, public domain I DON'T KNOW IF THIS EXISTS, let me know if someone already made it ^_^ What is BASEDNUM? ================= Natural, simple, elegant and beautiful way of representing all kinds of numbers in computers, including signed and unsigned integers and floating point numbers. A quick summary: - BASEDNUM unsigned integers are a generalization of direct representation. By adjusting a parameter integers slowly turn into logarithmic numbers. - BASEDNUM fractional numbers are a simple extension of BASEDNUM unsigned integers that turn them to a fixed or floating point data type, again all is controlled by a parameter. - BASEDNUM signed numbers are an extension of previous BASEDNUMs to allow negative values, giving us signed integers, signed fixed point and floating point. This is backwards compatible with two's complement. - Nice properties: - Values are never wasted, no duplicit or undefined values. - Zero is always represented by all zero bits. - Positive numbers can be compared with standard operators (>, <, <=, >=, ==, !=). - Unlike IEEE floats or Posits, everything is extremely simple, the number is generally just composed of two fixed-size parts. - Everything is baskwards compatible with two's complement, direct representation etc. BI(P,V) - N: Total number of bits. It is the sum of: - P: Number of bits representing parts. - V: Number of base number bits. _ _ _ _ ... _ _ _ _ ... \_________/ \_________/ P V \_____________________/ N x = 2^V * (2^p - 1) + (v + 1) * 2^p - 1 Examples: value TL(0,5) TL(1,4) TL(2,3) TL(3,2) TL(4,1) 00000 0 0 0 0 0 00001 1 1 1 1 1 00010 2 2 2 2 3 00011 3 3 3 3 5 00100 4 4 4 5 9 00101 5 5 5 7 13 00110 6 6 6 9 21 00111 7 7 7 11 29 01000 8 8 9 15 45 01001 9 9 11 19 61 01010 10 10 13 23 93 01011 11 11 15 27 125 01100 12 12 17 35 189 01101 13 13 19 43 253 01110 14 14 21 51 381 01111 15 15 23 59 509 10000 16 17 27 75 765 10001 17 19 31 91 1021 10010 18 21 35 107 1533 10011 19 23 39 123 2045 10100 20 25 43 155 3069 10101 21 27 47 187 4093 10110 22 29 51 219 6143 10111 23 31 55 251 8189 11000 24 33 63 315 12285 11001 25 35 71 379 16381 11010 26 37 79 443 24573 11011 27 39 87 507 32765 11100 28 41 95 635 49149 11101 29 43 103 763 65533 11110 30 45 111 891 98301 11111 31 47 119 1019 131069 x = 2^V * (2^p - 1) + (v + 1) * 2^p - 1 2^V * (2^p - 1) + (v + 1) * 2^p = x + 1 2^V * 2^p + 2^p * (v + 1) = x + 1 + 2^V 2^p = (x + 1 + 2^V) / (2^V + v + 1) p = log2((2^V + x + 1) / (2^V + v + 1)) 2^V * (2^p - 1) + (v + 1) * 2^p = x + 1 v = (x + 1 - 2^V * (2^p - 1)) / 2^p - 1 v = (x - 2^(V + p) + 2^V + 1) / 2^p - 1 BF(P,V,S,F) BS(P,V,S,F) 2^V * (2^p0 - 1) + (v0 + 1) * 2^p0 - 1 + 2^V * (2^p1 - 1) + (v1 + 1) * 2^p1 - 1 = 2^V * ((2^p0 - 1) + (2^p1 - 1)) + (v0 + 1) * 2^p0 + (v1 + 1) * 2^p1 - 2 2^V * (2^p0 + 2^p1 - 2) + (v0 + 1) * 2^p0 + (v1 + 1) * 2^p1 - 2 2^p2 = 2^p0 + 2^p1 - 1 p2 = log2(2^p0 + 2^p1 - 1) (v2 + 1) * 2^p2 = (v0 + 1) * 2^p0 + (v1 + 1) * 2^p1 - 1 v2 = ((v0 + 1) * 2^p0 + (v1 + 1) * 2^p1 - 1) / 2^p2 - 1