mmmPI wrote: Sat Mar 09, 2024 10:19 pmNow fractions sound a lot more complex, could be of real use for probabilities but i don't know if it would be a digression or not. I don't even know if it would differ in binary notation that just "non-integers" and how difficult it would be to do some pairwise operation showing a decimal parts in the results.
As you're getting the hang of hex, you may surprise yourself. You may need windows calculator in programming -> Hex mode though.
Code: Select all
0x01 * 0x80 = 0x0080 (1 * 128 = 128)
0x02 * 0x80 = 0x0100 (2 * 128 = 256)
0x03 * 0x80 = 0x0180 (3 * 128 = 384)
0x04 * 0x80 = 0x0200 (4 * 128 = 512)
0xFF * 0x80 = 0x7F80 (255 * 128 = 32640)
That's normal multiplies. Now I think you'd agree, even though these are integers, there could be a "decimal point" after each number. That 0x80 and 0x80.0 are the same number (even if it looks/feels weird).
All fractional stuff is doing, is moving that decimal point left. So now we have:
Code: Select all
0x01 * 0x.80 = 0x00.80 (1 * 0.5 = 0.5)
0x02 * 0x.80 = 0x01.00 (2 * 0.5 = 1.0)
0x03 * 0x.80 = 0x01.80 (3 * 0.5 = 1.5)
0x04 * 0x.80 = 0x02.00 (4 * 0.5 = 2.0)
0xFF * 0x.80 = 0x7F.80 (255 * 0.5 = 127.5)
0.8 is to hex what 0.5 is to decimal (8 being half way to 16).
So by multiplying numbers by 128, and keeping track of where the decimal point is, we've been able to divide by two.
This is known as "fixed point" maths, as we're using values with decimal points in a fixed position. In the example above, I'd put the decimal point 8 bits to the left.
With "floating point" maths, the computer tracks where the decimal point is for each number, so that you don't have to try and figure out where to place it for your maths. It "floats" around, giving the numbers a lot more dynamic range, and making calculations easier.
But it's not always necessary, you can do a lot without the computer explicitly tracking it for you, when you want/need to.
The multiplier:
Here, I've attached a demo, including the "very fast multiplier" for those that might want to borrow it
You can enter a "number to count to" (Limit) for as many signals as you like in one combinator. In the other combinator, enter how many seconds each count should take (Period). There's many ways this could be done, but here, we're going to use a fractional multiply.
So what we're going to do is have each signal count from 0x00000000 to 0xFFFFFFFF, or [0..1), and call it "Position". Each tick, we're going to add (2^32 / (PERIOD * 60)) to the Position, the 60 being due how many ticks are in a second.
With that done, Output = (Position * Limit) / 2^32, or MULHU.
NB: I'm using MULHU/MULHS now, it's more common parlance and I like to add to confusion.
Anyway, enjoy - maybe you can find some use for it