Skip to content

Instantly share code, notes, and snippets.

@CryZe
Last active March 24, 2024 21:13
Show Gist options
  • Select an option

  • Save CryZe/30cc76f4629cb0846d5a9b8d13144649 to your computer and use it in GitHub Desktop.

Select an option

Save CryZe/30cc76f4629cb0846d5a9b8d13144649 to your computer and use it in GitHub Desktop.
Survey of Floating Point Implementations for Maximum

Survey of Floating Point Implementations for Maximum

Following some IEEE Standard

IEEE Std 754-2008 maxNum (NaN Absorb, 0 implementation defined)

  • C17 fmax
  • Rust f64::max
  • LLVM llvm.maxnum
  • ARM FMAXNM (either mode)

IEEE Std 754-2019 maximum (NaN Prop, -0 < +0)

  • EcmaScript Math.max
  • WebAssembly fmax
  • ARM FMAX (canonical mode)
  • Java Math.max
  • Go math.Max (doesn't have -0 literals?!)
  • LLVM llvm.maximum
  • Rust f64::maximum

IEEE Std 754-2019 maximumNumber (NaN Absorb, -0 < +0)

  • ARM FMAXNM (canonical mode)

Following a fast implementation

if a < b { b } else { a } (prefer left hand side)

  • C++20 std::max
  • Python math.max
  • WebAssembly SIMD pmax

if b < a { a } else { b } (prefer right hand side)

  • Intel x86 MAXPS

Others

NaN Prop, -0 == +0, prefer right hand side

  • C# Math.Max
  • ARM FMAX (ARMv8.7-A FEAT_AFP + AH bit = 1)

Ignore NaN, prefer left hand side, except for -0 and +0, then prefer right hand side

  • Swift max
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment