Technology1 min read

The VHDL standard's float package gets sqrt(2) wrong

By · Published by Everything Blog

In short

The official `ieee.float_pkg` included in the IEEE Std 1076-2008 and 1076-2019 specifications consistently fails baseline arithmetic validations against exact mathematical references. Beyond simple operations yielding off-by-one results, utility functions like `resize` can cause simulator crashes due to out-of-bounds errors, miscalculate exponents, or generate false infinities. Extensive stress testing indicates that these mathematical faults persist across multiple floating-point formats and non-standard rounding modes.

Key points

  • The standard `ieee.float_pkg` library distributed with simulators such as GHDL and NVC co…: The standard `ieee.float_pkg` library distributed with simulators such as GHDL and NVC contains pervasive mathematical inaccuracies.
  • Formatting routines in the package introduce critical stability risks by triggering simul…: Formatting routines in the package introduce critical stability risks by triggering simulator crashes and generating invalid infinite values.
  • Calculation discrepancies persist and often escalate across alternative rounding modes, i…: Calculation discrepancies persist and often escalate across alternative rounding modes, including round-to-zero and directed infinities.

Sources checked by our analysis pipeline: 1

ieee.float_pkg

is the floating-point package of the VHDL standard, IEEE Std 1076-2008 and 1076-2019. The source is the IEEE's own: ieee/float_generic_pkg-body.vhdl

on the release

branch of opensource.ieee.org/vasg/Packages

, 5,712 lines, $Revision: 1220 $

. The working group's develop

branch at gitlab.com/IEEE-P1076/Packages

has the same bytes, and GHDL and NVC ship them unchanged. The runs here are in GHDL 7.0.0-dev and NVC 1.23.1, and where both ran the same vectors they wrote the same result file.

The package is set beside exact arithmetic. An operand is a sign and a fraction of two integers, the operation is done on the fractions, and the result is rounded once into the format in the rounding style the call names. exact.py

is that reference.

With the package's own settings: round_nearest

, 3 guard bits, denormal numbers on.

call returns exactly rounded

sqrt (2.0) in float64 3FF6A09E667F3BCC 3FF6A09E667F3BCD

sqrt (14.0) 406F7750 406F7751

sqrt (2.0**-149) 4.2e-22 3.7e-23

mac (-6.0, -1.0, -5.0) -15.0 1.0

mac (-5.0, 1.0, 4.0) 15.0 -1.0

mac (1.0, 1.0, -infinity) +infinity -infinity

mac (1 + 2.0**-23, 1 - 2.0**-23, -1.0) -2.0**-26 -2.0**-46

resize…

Technology