The VHDL standard's float package gets sqrt(2) wrong github.com · 15 points · 8 ...

@best

The VHDL standard's float package gets sqrt(2) wrong github.com · 15 points · 8 comments · HN thread

TL;DR The author reports that the IEEE 1076-2008/2019 VHDL float_pkg (shipped unchanged in GHDL and NVC) returns wrong results for many ordinary operations, including sqrt(2.0) in float64 one unit in the last place too low, and mac(-6,-1,-5) returning -15 instead of 1. They ran about 8.7 million calls on a 7-bit format and roughly 1.27 million were not correctly rounded, and they provide a patched package that passes all their tests. Fixed-point divide in ieee.fixed_pkg is also reported wrong in about 5% of cases, with a patch.

  • Standard float_pkg (IEEE 1076-2008/2019) returns sqrt(2.0) in float64 one ulp low; sqrt uses a fixed number of Newton steps with no sticky bit.
  • Operations including mac, divide, reciprocal, resize, scalb and to_signed/to_unsigned return wrong values; examples include resize of 2^-512 to float32 giving 1.0 and reciprocal of 2^127 in float32 giving infinity.
  • Testing 10,000 operand/rounding-style cases per operation found 371,873 wrong results across four formats, plus 1,302 simulator stops; the patched package gives zero wrong on the same vectors.
  • GHDL and NVC produced identical result files for both the shipped and patched packages, and the author reports the bugs to IEEE P1076 (VHDL-Issues 388), ghdl 3486 and nvc 1758.
  • ieee.fixed_pkg divide is wrong in 41,026 of 751,418 calls because guard bits ignore the division remainder; a patch fixes this in the tested set.

Discussion The thread is short and mostly about the readability and presentation of the write-up rather than the substance. Early commenters had trouble opening the first link on mobile and found the text hard to follow. One commenter asked for error sizes in ULPs, and the author answered with a breakdown showing many errors are far beyond one ulp. A few commenters dismissed the practical impact, noting that raw sqrt is rarely fed straight into synthesis, and one commenter mocked the write-up as machine-generated. The mood is skeptical and mildly mocking, with the technical claims getting little direct challenge.

  • The write-up is too dense and hard for humans to read (many): Several commenters found the post unreadable and said it needed a clearer high-level explanation. The author acknowledged the prose was rushed and pointed readers to the numbers instead.
  • Error size in ULPs matters more than the bare fact of error (some): One commenter wanted to know how far off results are, since a one-ulp error is less newsworthy than large errors. The author replied that many errors are over 1,000 ulps and that wrong signs and infinity/NaN confusions are common.
  • Practical impact is small because raw sqrt is not synthesized directly (a few): One commenter argued that hardware designers do not feed raw sqrt into synthesis, so a one-ulp error matters little in practice. This view was not contested in the thread.
  • A foundational library should be fully correct to the ulp (a few): One commenter argued that a foundational numeric library should be exactly correct, so even small errors deserve attention.

#VHDL #floatingPoint #hardware #GHDL #NVC #numerics