Skip to content

introduce new float types; remove @setFloatMode #23173

@andrewrk

Description

@andrewrk

Rather than a setting, there will be new float types:

  • real16
  • real32
  • real64
  • real128

These types guarantee @sizeOf but otherwise have non-well-defined memory layout. @bitCast is not allowed on this type, and they are not allowed in extern or packed structs. This is a conservative choice that may or may not be relaxed in a future proposal.

These types are different than their f16, f32, f64, and f128 counterparts in that:

  • They cannot store NaN, -inf, or +inf.
    • No operations can produce +inf or -inf. If they would, checked illegal behavior occurs instead.
    • No operations can produce NaN. If they would, checked illegal behavior occurs instead.
    • Saturating arithmetic can be used to avoid potential illegal behavior.
  • Cannot distinguish between positive or negative zero.
  • Arithmetic operations do not follow IEEE float semantics. They may:
    • Produce different results on different targets
    • Produce different results in different optimization modes
    • Use the reciprocal of an argument rather than perform division.
    • Perform floating-point contraction (e.g. fusing a multiply followed by an addition into a fused multiply-add).
    • Perform algebraically equivalent transformations that may change results in floating point (e.g. reassociate)
    • Any operation may use any rounding mode.

Reals implicitly coerce into floats, however, @realFromFloat is required to convert a float to real, which invokes checked illegal behavior if the value is NaN, -inf, or inf.

@setFloatMode is to be eliminated.

Users would be encouraged to choose real types unless deterministic IEEE floating point semantics are required. Therefore, the floating point types would be renamed to float16, float32, float64, and float128.

Metadata

Metadata

Assignees

No one assigned

    Labels

    acceptedThis proposal is planned.proposalThis issue suggests modifications. If it also has the "accepted" label then it is planned.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions