The VHDL standard's own float package returns the wrong answer for sqrt(2)
The VHDL standard's float package gets sqrt(2) wrong
An audit of ieee.float_pkg, the floating-point package shipped in IEEE 1076-2008 and 1076-2019 and bundled unchanged in GHDL and NVC, compares every operation against exact arithmetic. Plain calls already fail: sqrt(2.0) in float64 lands one unit off, mac(-6.0, -1.0, -5.0) returns -15.0, and some resizes crash the simulator. Across 10,000-call sweeps, mac is wrong roughly a quarter of the time under round_nearest, and sqrt misses 735 of 10,000 float32 cases. The author traces each fault to specific lines and offers a 33-hunk patch.
Of the integers 1 to 4,096, sqrt returns a float32 one unit off for 256 and a float64 one unit off for 264.
- bee_rider
The first link in the post doesn’t seem to be valid (on my iPhone at least). Maybe it is an issue of mobile safari not wanting to open… a vhdl blob, though? Maybe double check that, a link to their main page could be more useful.
[edit, it seemed to work the second time, I dunno, maybe it was just a temporary issue, sorry!]
Also, it looks like in the last six minutes (as of me writing this post) the README was updated with an intro that starts thing off with a better high-level description of what’s going on. I think the write-up could still use some work. But it isn’t entirely useless, really, this sort of library should be fully correct, down to the ULP, it is quite foundational after all.
- rustybolt
My god this is utterly unreadable for humans.
- IshKebab
... by one ULP. Anyway I don't think anyone is just feeding a raw sqrt into their synthesiser.