I'm not sure if this is a roc issue... but I had a crack at packing two F32's into a U64 and can't quite get it to work. I've had a heap of help from different LLMs, but I'm getting a single test failure which I think may be roc related.
https://gist.github.com/lukewilliamboswell/3257ea8f5d7251a86e396b590987011c
Just wondering if we fuzzed these functions? is it worth exploring further?
── EXPECT FAILED in platform/InternalVector2.roc ───────────────────────────────
This expectation failed:
123│> expect
124│> # Test 8: Different exponents with fractions
125│> parts1 = { sign: Bool.false, exponent: 130, fraction: 0x00555555 }
126│> parts2 = { sign: Bool.false, exponent: 125, fraction: 0x00AAAAAA }
127│> num1 = Num.f32FromParts parts1
128│> num2 = Num.f32FromParts parts2
129│> components = { x: num1, y: num2 }
130│> packed = pack components
131│> unpacked = unpack packed
132│> num1unpacked = Num.f32ToParts unpacked.x
133│> num2unpacked = Num.f32ToParts unpacked.y
134│> num1unpacked == parts1 && num2unpacked == parts2
When it failed, these variables had these values:
parts1 : {
exponent : Int Unsigned8,
fraction : Int Unsigned32,
sign : Bool,
}
parts1 = { exponent: 130, fraction: 5592405, sign: Bool.false }
parts2 : {
exponent : Int Unsigned8,
fraction : Int Unsigned32,
sign : Bool,
}
parts2 = { exponent: 125, fraction: 11184810, sign: Bool.false }
num1 : F32
num1 = 13.333333
num2 : F32
num2 = 0.3333333
components : {
x : F32,
y : F32,
}
components = { x: 13.333333, y: 0.3333333 }
packed : Vector2D
packed = @Vector2D 4515609224609617237
unpacked : {
x : F32,
y : F32,
}
unpacked = { x: 13.333333, y: 0.3333333 }
num1unpacked : {
exponent : Int Unsigned8,
fraction : Int Unsigned32,
sign : Bool,
}
num1unpacked = { exponent: 130, fraction: 5592405, sign: Bool.false }
num2unpacked : {
exponent : Int Unsigned8,
fraction : Int Unsigned32,
sign : Bool,
}
num2unpacked = { exponent: 125, fraction: 2796202, sign: Bool.false }
1 failed and 10 passed in 606 ms.
So the bug is the fraction of the second number
It looks that way
Oh, actually the bug is your input
Your fraction is getting truncated cause it is too large
Ahk, that's good to know
That first A should be a 2
Cause the highest bit is invalid to set in the fraction. It is bit 24
You only get 23 bits
This is where arbitrary precision ints would be really nice
It's probably worth giving this a shot over RocVector2 := { x : F32, y : F32, unused : I64, unused2 : I64, unused3 : I64, unused4 : I64 }
eh?
Should be more efficient?
Either is probably fast enough
Ok, I'll leave it for now then. What I have now is much simpler and easy to change
Just didn't use a list of the of the wasteful one
Yeah, there's going to be lot's of extra allocations and unused space until we fix the ABI bug
Last updated: Jul 06 2025 at 12:14 UTC