Skip to main content
Z3 implements the IEEE 754 standard for floating-point arithmetic, providing precise reasoning about floating-point operations including rounding modes, special values (NaN, infinity), and numerical properties.

Floating-Point Sorts

Standard Formats

Create standard IEEE 754 floating-point sorts:
C API:
  • Z3_mk_fpa_sort_16(c) - half precision (api_fpa.cpp:182)
  • Z3_mk_fpa_sort_32(c) - single precision (api_fpa.cpp:190)
  • Z3_mk_fpa_sort_64(c) - double precision (api_fpa.cpp:198)
  • Z3_mk_fpa_sort_128(c) - quadruple precision (api_fpa.cpp:206)

Custom Formats

Create custom floating-point formats:
C API: Z3_mk_fpa_sort(c, ebits, sbits) (api_fpa.cpp:164)

Rounding Modes

IEEE 754 defines five rounding modes:
C API:
  • Z3_mk_fpa_rne(c) - round nearest ties to even (api_fpa.cpp:64)
  • Z3_mk_fpa_rna(c) - round nearest ties away (api_fpa.cpp:86)
  • Z3_mk_fpa_rtp(c) - round toward positive (api_fpa.cpp:108)
  • Z3_mk_fpa_rtn(c) - round toward negative (api_fpa.cpp:130)
  • Z3_mk_fpa_rtz(c) - round toward zero (api_fpa.cpp:152)

Special Values

NaN (Not a Number)

C API: Z3_mk_fpa_nan(c, s) (api_fpa.cpp:210)

Infinity

C API: Z3_mk_fpa_inf(c, s, negative) (api_fpa.cpp:226)

Zero

Floating-point has both positive and negative zero:
C API: Z3_mk_fpa_zero(c, s, negative) (api_fpa.cpp:243)

Floating-Point Literals

From Decimal

C API:
  • Z3_mk_fpa_numeral_float(c, v, ty) (api_fpa.cpp:275)
  • Z3_mk_fpa_numeral_double(c, v, ty) (api_fpa.cpp:295)

From IEEE Bit Representation

Construct from sign, exponent, and significand bits:
C API: Z3_mk_fpa_fp(c, sgn, exp, sig) (api_fpa.cpp:260)

Arithmetic Operations

All floating-point operations require a rounding mode:

Addition

Subtraction

Multiplication

Division

Remainder

Fused Multiply-Add

Compute (x * y) + z with single rounding:

Square Root

Absolute Value and Negation

Min and Max

Comparison Operations

Equality and Inequality

Ordered Comparisons

IEEE Predicates

Conversion Operations

Between Floating-Point Formats

To/From Real

To/From Integers

To/From Bit-Vectors

Complete Examples

Example 1: Rounding Error

Example 2: Division by Zero

Example 3: Overflow Detection

Example 4: Precision Loss

Example 5: NaN Propagation

Example 6: Correctly Rounded Result

Advanced Features

Subnormal Numbers

Numbers smaller than the smallest normalized number:

Rounding Mode Effects

Implementation Notes

  • Follows IEEE 754-2008 standard precisely
  • All operations require explicit rounding modes
  • NaN propagates through computations
  • Special handling for signed zeros
  • Supports directed rounding for interval arithmetic

References

  • Implementation: src/api/api_fpa.cpp
  • Theory plugin: src/ast/fpa_decl_plugin.h
  • Solver: src/smt/theory_fpa.h
  • IEEE 754 Standard: IEEE Standard for Floating-Point Arithmetic (IEEE 754-2008)