Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Variable Length BCD Floating Point Number implementation "draft"
- Binary Values:
- 0000 (0) -> 0 \
- 0001 (1) -> 1 |
- 0010 (2) -> 2 |
- 0011 (3) -> 3 |
- 0100 (4) -> 4 |
- 0101 (5) -> 5 |--- Regular BCD values
- 0110 (6) -> 6 |
- 0111 (7) -> 7 |
- 1000 (8) -> 8 |
- 1001 (9) -> 9 /
- 1010 (A) ->
- 1011 (B) ->
- 1100 (C) -> [ ---- Repeat block start
- 1101 (D) ->
- 1110 (E) -> . ---- Decimal point
- 1111 (F) -> T ---- Number terminator
- the values between the Repeat block start and the Number terminator indicate that those digits repeat indefinitely beyond the end of the number. Which is used to extend numbers to be of equal length before doing any arithmetics.
- Because all digits/control characters are nibbles, numbers need to be padded out to full bytes. this is done using Number terminators at the end.
- example:
- decimal: 2309.16321
- BCDf: 23 09 E1 63 21 FF (2 terminators since 1 wouldn't fill out a byte)
- decimal: 0.6123333333...
- BCDf: 0E 61 2C 3F
- decimal: 0.876876876876...
- BCDf: 0E C8 76 FF
- 0.00000000000001 + 0.333...
- 0E 00 00 00 00 00 00 01 FF + 0E C3 FF
- 0E C3 FF
- is extended to:
- 0E 33 33 33 33 33 33 33 FF
- to match the other value in length (after the decimal point), from there the math is simple:
- 0E 00 00 00 00 00 00 01 FF + 0E 33 33 33 33 33 33 33 FF
- = 0E 33 33 33 33 33 33 34 FF (0.33333333333334)
- another thing i thought about was having a repeat block end "]" and repeat count marker "@".
- those would be used to create repeat blocks within a number (instead of just the end) to repeat a certain set of digits n amount of times.
- for example "@5[32]" would be the same as "3232323232" as it repeats "32" "5" times.
- all that would do is reduce the memory footprint of numbers with lots of repeating digits, like 0.000000000000176 -> 0.@12[0]176T. but of course that comes at the expense of having to convert/expand numbers before doing math, and convert/compress them back afterwards (if possible).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement