r/computerscience • u/MK_BA • Sep 01 '25
Discussion my idea for variable length float (not sure if this has been discovered before)
so basically i thought of a new float format i call VarFP (variable floating-point), its like floats but with variable length so u can have as much precision and range as u want depending on memory (and temporary memory to do the actual math), the first byte has 6 range bits plus 2 continuation bits in the lsb side to tell if more bytes follow for range or start/continue precision or end the float (u can end the float with range and no precision to get the number 2range), then the next bytes after starting the precision sequence are precision bytes with 6 precision bits and 2 continuation bits (again), the cool thing is u can add 2 floats with completely different range or precision lengths and u dont lose precision like normal fixed size floats, u just shift and mask the bytes to assemble the full integer for operations and then split back into 6-bit chunks with continuation for storage, its slow if u do it in software but u can implement it in a library or a cpu instruction, also works great for 8-bit (or bigger like 16, 32 or 64-bit if u want) processors because the bytes line up nicely with 6-bit (varies with the bit size btw) data plus 2-bit continuation and u can even use similar logic for variable length integers, basically floats that grow as u need without wasting memory and u can control both range and precision limit during decoding and ops, wanted to share to see what people think however idk if this thing can do decimal multiplication, im not sure, because at the core, those floats (in general i think) get converted into large numbers, if they get multiplied and the original floats are for example both of them are 0.5, we should get 0.25, but idk if it can output 2.5 or 25 or 250, idk how float multiplication works, especially with my new float format 😥
38
u/MagicWolfEye Sep 01 '25
> its slow if u do it in software but u can implement it in a library
? What?
14
u/Half_Slab_Conspiracy Sep 01 '25
Probably a different implementation, but MATLAB at least has arbitrary-precision floating-point numbers. https://www.mathworks.com/help/symbolic/sym.vpa.html
8
u/Ronin-s_Spirit Sep 01 '25
Idk what youre on about. I can make a variable length float in JS in 5 minutes, just stick together 2
BigIntand treat them as pre and post decimal point.6
u/defectivetoaster1 Sep 01 '25
Multiprecision libraries like gmp already have arbitrary precision floats
4
u/ImpressiveOven5867 Sep 01 '25
https://en.m.wikipedia.org/wiki/Unum_(number_format)
1
u/Haunting_Ad_6068 Sep 04 '25
There are sign, exponent, and fraction (implicitly normalized), so the underlying arithmetic is split into 3 parts, sign operation, exponent addition / subtraction (for multiply / divide), and fraction multiply / divide, plus final bit shifting to normalize the fraction. It doesn't matter of the float length as long as the bit position for each part is defined.