The Lean Language Reference

18.6.Β Floating-Point NumbersπŸ”—

Floating-point numbers are a an approximation of the real numbers that are efficiently implemented in computer hardware. Computations that use floating-point numbers are very efficient; however, the nature of the way that they approximate the real numbers is complex, with many corner cases. The IEEE 754 standard, which defines the floating-point format that is used on modern computers, allows hardware designers to make certain choices, and real systems differ in these small details. For example, there are many distinct bit representations of NaN, the indicator that a result is undefined, and some platforms differ with respect to which NaN is returned from adding two NaNs.

Lean exposes the underlying platform's floating-point values for use in programming, but they are not encoded in Lean's logic. They are represented by an opaque type. This means that the kernel is not capable of computing with or reasoning about floating-point values without additional axioms. A consequence of this is that equality of floating-point numbers is not decidable. Furthermore, comparisons between floating-point values are decidable, but the code that does so is opaque; in practice, the decision procedure can only be used in compiled code.

Lean provides two floating-point types: Float represents 64-bit floating point values, while Float32 represents 32-bit floating point values. The precision of Float does not vary based on the platform that Lean is running on.

πŸ”—type
Float : Type

64-bit floating-point numbers.

Float corresponds to the IEEE 754 binary64 format (double in C or f64 in Rust). Floating-point numbers are a finite representation of a subset of the real numbers, extended with extra β€œsentinel” values that represent undefined and infinite results as well as separate positive and negative zeroes. Arithmetic on floating-point numbers approximates the corresponding operations on the real numbers by rounding the results to numbers that are representable, propagating error and infinite values.

Floating-point numbers include subnormal numbers. Their special values are:

  • NaN, which denotes a class of β€œnot a number” values that result from operations such as dividing zero by zero, and

  • Inf and -Inf, which represent positive and infinities that result from dividing non-zero values by zero.

πŸ”—type
Float32 : Type

32-bit floating-point numbers.

Float32 corresponds to the IEEE 754 binary32 format (float in C or f32 in Rust). Floating-point numbers are a finite representation of a subset of the real numbers, extended with extra β€œsentinel” values that represent undefined and infinite results as well as separate positive and negative zeroes. Arithmetic on floating-point numbers approximates the corresponding operations on the real numbers by rounding the results to numbers that are representable, propagating error and infinite values.

Floating-point numbers include subnormal numbers. Their special values are:

  • NaN, which denotes a class of β€œnot a number” values that result from operations such as dividing zero by zero, and

  • Inf and -Inf, which represent positive and infinities that result from dividing non-zero values by zero.

No Kernel Reasoning About Floating-Point Numbers

The Lean kernel can compare expressions of type Float for syntactic equality, so 0.0 is definitionally equal to itself.

example : (0.0 : Float) = (0.0 : Float) := ⊒ 0.0 = 0.0 All goals completed! πŸ™

Terms that require reduction to become syntactically equal cannot be checked by the kernel:

example : (0.0 : Float) = (0.0 + 0.0 : Float) := ⊒ 0.0 = 0.0 + 0.0 ⊒ 0.0 = 0.0 + 0.0
tactic 'rfl' failed, the left-hand side
  0.0
is not definitionally equal to the right-hand side
  0.0 + 0.0
⊒ 0.0 = 0.0 + 0.0

Similarly, the kernel cannot evaluate Bool-valued comparisons of floating-point numbers while checking definitional equality:

theorem Float.zero_eq_zero_plus_zero : ((0.0 : Float) == (0.0 + 0.0 : Float)) = true := ⊒ (0.0 == 0.0 + 0.0) = true ⊒ (0.0 == 0.0 + 0.0) = true
tactic 'rfl' failed, the left-hand side
  0.0 == 0.0 + 0.0
is not definitionally equal to the right-hand side
  true
⊒ (0.0 == 0.0 + 0.0) = true

However, the native_decide tactic can invoke the underlying platform's floating-point primitives that are used by Lean for run-time programs:

theorem Float.zero_eq_zero_plus_zero : ((0.0 : Float) == (0.0 + 0.0 : Float)) = true := ⊒ (0.0 == 0.0 + 0.0) = true All goals completed! πŸ™

This tactic uses the axiom Lean.ofReduceBool, which states that the Lean compiler, interpreter and the low-level implementations of built-in operators are trusted in addition to the kernel.

'Float.zero_eq_zero_plus_zero' depends on axioms: [propext, Classical.choice, Lean.ofReduceBool]#print axioms Float.zero_eq_zero_plus_zero
'Float.zero_eq_zero_plus_zero' depends on axioms: [propext, Classical.choice, Lean.ofReduceBool]
Floating-Point Equality Is Not Reflexive

Floating-point operations may produce NaN values that indicate an undefined result. These values are not comparable with each other; in particular, all comparisons involving NaN will return false, including equality.

false#eval ((0.0 : Float) / 0.0) == ((0.0 : Float) / 0.0)
Floating-Point Equality Is Not a Congruence

Applying a function to two equal floating-point numbers may not result in equal numbers. In particular, positive and negative zero are distinct values that are equated by floating-point equality, but division by positive or negative zero yields positive or negative infinite values.

def neg0 : Float := -0.0 def pos0 : Float := 0.0 (true, false)#eval (neg0 == pos0, 1.0 / neg0 == 1.0 / pos0)
(true, false)

18.6.1.Β Syntax

Lean does not have dedicated floating-point literals. Instead, floating-point literals are resolved via the appropriate instances of the OfScientific and Neg type classes.

Floating-Point Literals

The term

(-2.523 : Float)

is syntactic sugar for

(Neg.neg (OfScientific.ofScientific 22523 true 4) : Float)

and the term

(413.52 : Float32)

is syntactic sugar for

(OfScientific.ofScientific 41352 true 2 : Float32)

18.6.2.Β API ReferenceπŸ”—

18.6.2.1.Β Properties

Floating-point numbers fall into one of three categories:

  • Finite numbers are ordinary floating-point values.

  • Infinities, which may be positive or negative, result from division by zero.

  • NaNs, which are not numbers, result from other undefined operations, such as the square root of a negative number.

πŸ”—opaque
Float.isInf : Float β†’ Bool

Checks whether a floating-point number is a positive or negative infinite number, but not a finite number or NaN.

This function does not reduce in the kernel. It is compiled to the C operator isinf.

πŸ”—opaque
Float32.isInf : Float32 β†’ Bool

Checks whether a floating-point number is a positive or negative infinite number, but not a finite number or NaN.

This function does not reduce in the kernel. It is compiled to the C operator isinf.

πŸ”—opaque
Float.isNaN : Float β†’ Bool

Checks whether a floating point number is NaN (β€œnot a number”) value.

NaN values result from operations that might otherwise be errors, such as dividing zero by zero.

This function does not reduce in the kernel. It is compiled to the C operator isnan.

πŸ”—opaque
Float32.isNaN : Float32 β†’ Bool

Checks whether a floating point number is NaN ("not a number") value.

NaN values result from operations that might otherwise be errors, such as dividing zero by zero.

This function does not reduce in the kernel. It is compiled to the C operator isnan.

πŸ”—opaque
Float.isFinite : Float β†’ Bool

Checks whether a floating-point number is finite, that is, whether it is normal, subnormal, or zero, but not infinite or NaN.

This function does not reduce in the kernel. It is compiled to the C operator isfinite.

πŸ”—opaque
Float32.isFinite : Float32 β†’ Bool

Checks whether a floating-point number is finite, that is, whether it is normal, subnormal, or zero, but not infinite or NaN.

This function does not reduce in the kernel. It is compiled to the C operator isfinite.

18.6.2.2.Β Syntax

These operations exist to support the OfScientific Float and OfScientific Float32 instances and are normally invoked indirectly as a result of a literal value.

πŸ”—opaque
Float.ofScientific (m : Nat) (s : Bool)
  (e : Nat) : Float

Constructs a Float from the given mantissa, sign, and exponent values.

This function is part of the implementation of the OfScientific Float instance that is used to interpret floating-point literals.

πŸ”—opaque
Float32.ofScientific (m : Nat) (s : Bool)
  (e : Nat) : Float32

Constructs a Float32 from the given mantissa, sign, and exponent values.

This function is part of the implementation of the OfScientific Float32 instance that is used to interpret floating-point literals.

18.6.2.3.Β Conversions

πŸ”—opaque
Float.toBits : Float β†’ UInt64

Bit-for-bit conversion to UInt64. Interprets a Float as a UInt64, ignoring the numeric value and treating the Float's bit pattern as a UInt64.

Floats and UInt64s have the same endianness on all supported platforms. IEEE 754 very precisely specifies the bit layout of floats.

This function is distinct from Float.toUInt64, which attempts to preserve the numeric value rather than reinterpreting the bit pattern.

πŸ”—opaque
Float32.toBits : Float32 β†’ UInt32

Bit-for-bit conversion to UInt32. Interprets a Float32 as a UInt32, ignoring the numeric value and treating the Float32's bit pattern as a UInt32.

Float32s and UInt32s have the same endianness on all supported platforms. IEEE 754 very precisely specifies the bit layout of floats.

This function is distinct from Float.toUInt32, which attempts to preserve the numeric value rather than reinterpreting the bit pattern.

This function does not reduce in the kernel.

πŸ”—opaque
Float.ofBits : UInt64 β†’ Float

Bit-for-bit conversion from UInt64. Interprets a UInt64 as a Float, ignoring the numeric value and treating the UInt64's bit pattern as a Float.

Floats and UInt64s have the same endianness on all supported platforms. IEEE 754 very precisely specifies the bit layout of floats.

This function does not reduce in the kernel.

πŸ”—opaque
Float32.ofBits : UInt32 β†’ Float32

Bit-for-bit conversion from UInt32. Interprets a UInt32 as a Float32, ignoring the numeric value and treating the UInt32's bit pattern as a Float32.

Float32s and UInt32s have the same endianness on all supported platforms. IEEE 754 very precisely specifies the bit layout of floats.

This function does not reduce in the kernel.

πŸ”—opaque
Float.toFloat32 : Float β†’ Float32

Converts a 64-bit floating-point number to a 32-bit floating-point number. This may lose precision.

This function does not reduce in the kernel.

πŸ”—opaque
Float32.toFloat : Float32 β†’ Float

Converts a 32-bit floating-point number to a 64-bit floating-point number.

This function does not reduce in the kernel.

πŸ”—opaque
Float.toString : Float β†’ String

Converts a floating-point number to a string.

This function does not reduce in the kernel.

πŸ”—opaque
Float32.toString : Float32 β†’ String

Converts a floating-point number to a string.

This function does not reduce in the kernel.

πŸ”—opaque
Float.toUInt8 : Float β†’ UInt8

Converts a floating-point number to an 8-bit unsigned integer.

If the given Float is non-negative, truncates the value to a positive integer, rounding down and clamping to the range of UInt8. Returns 0 if the Float is negative or NaN, and returns the largest UInt8 value (i.e. UInt8.size - 1) if the float is larger than it.

This function does not reduce in the kernel.

πŸ”—opaque
Float.toInt8 : Float β†’ Int8

Truncates a floating-point number to the nearest 8-bit signed integer, rounding towards zero.

If the Float is larger than the maximum value for Int8 (including Inf), returns the maximum value of Int8 (i.e. Int8.maxValue). If it is smaller than the minimum value for Int8 (including -Inf), returns the minimum value of Int8 (i.e. Int8.minValue). If it is NaN, returns 0.

This function does not reduce in the kernel.

πŸ”—opaque
Float32.toUInt8 : Float32 β†’ UInt8

Converts a floating-point number to an 8-bit unsigned integer.

If the given Float32 is non-negative, truncates the value to a positive integer, rounding down and clamping to the range of UInt8. Returns 0 if the Float32 is negative or NaN, and returns the largest UInt8 value (i.e. UInt8.size - 1) if the float is larger than it.

This function does not reduce in the kernel.

πŸ”—opaque
Float32.toInt8 : Float32 β†’ Int8

Truncates a floating-point number to the nearest 8-bit signed integer, rounding towards zero.

If the Float is larger than the maximum value for Int8 (including Inf), returns the maximum value of Int8 (i.e. Int8.maxValue). If it is smaller than the minimum value for Int8 (including -Inf), returns the minimum value of Int8 (i.e. Int8.minValue). If it is NaN, returns 0.

This function does not reduce in the kernel.

πŸ”—opaque
Float.toUInt16 : Float β†’ UInt16

Converts a floating-point number to a 16-bit unsigned integer.

If the given Float is non-negative, truncates the value to a positive integer, rounding down and clamping to the range of UInt16. Returns 0 if the Float is negative or NaN, and returns the largest UInt16 value (i.e. UInt16.size - 1) if the float is larger than it.

This function does not reduce in the kernel.

πŸ”—opaque
Float.toInt16 : Float β†’ Int16

Truncates a floating-point number to the nearest 16-bit signed integer, rounding towards zero.

If the Float is larger than the maximum value for Int16 (including Inf), returns the maximum value of Int16 (i.e. Int16.maxValue). If it is smaller than the minimum value for Int16 (including -Inf), returns the minimum value of Int16 (i.e. Int16.minValue). If it is NaN, returns 0.

This function does not reduce in the kernel.

πŸ”—opaque
Float32.toUInt16 : Float32 β†’ UInt16

Converts a floating-point number to a 16-bit unsigned integer.

If the given Float32 is non-negative, truncates the value to a positive integer, rounding down and clamping to the range of UInt16. Returns 0 if the Float32 is negative or NaN, and returns the largest UInt16 value (i.e. UInt16.size - 1) if the float is larger than it.

This function does not reduce in the kernel.

πŸ”—opaque
Float32.toInt16 : Float32 β†’ Int16

Truncates a floating-point number to the nearest 16-bit signed integer, rounding towards zero.

If the Float is larger than the maximum value for Int16 (including Inf), returns the maximum value of Int16 (i.e. Int16.maxValue). If it is smaller than the minimum value for Int16 (including -Inf), returns the minimum value of Int16 (i.e. Int16.minValue). If it is NaN, returns 0.

This function does not reduce in the kernel.

πŸ”—opaque
Float.toUInt32 : Float β†’ UInt32

Converts a floating-point number to a 32-bit unsigned integer.

If the given Float is non-negative, truncates the value to a positive integer, rounding down and clamping to the range of UInt32. Returns 0 if the Float is negative or NaN, and returns the largest UInt32 value (i.e. UInt32.size - 1) if the float is larger than it.

This function does not reduce in the kernel.

πŸ”—opaque
Float32.toUInt32 : Float32 β†’ UInt32

Converts a floating-point number to a 32-bit unsigned integer.

If the given Float32 is non-negative, truncates the value to a positive integer, rounding down and clamping to the range of UInt32. Returns 0 if the Float32 is negative or NaN, and returns the largest UInt32 value (i.e. UInt32.size - 1) if the float is larger than it.

This function does not reduce in the kernel.

πŸ”—opaque
Float.toInt32 : Float β†’ Int32

Truncates a floating-point number to the nearest 32-bit signed integer, rounding towards zero.

If the Float is larger than the maximum value for Int32 (including Inf), returns the maximum value of Int32 (i.e. Int32.maxValue). If it is smaller than the minimum value for Int32 (including -Inf), returns the minimum value of Int32 (i.e. Int32.minValue). If it is NaN, returns 0.

This function does not reduce in the kernel.

πŸ”—opaque
Float32.toInt32 : Float32 β†’ Int32

Truncates a floating-point number to the nearest 32-bit signed integer, rounding towards zero.

If the Float is larger than the maximum value for Int32 (including Inf), returns the maximum value of Int32 (i.e. Int32.maxValue). If it is smaller than the minimum value for Int32 (including -Inf), returns the minimum value of Int32 (i.e. Int32.minValue). If it is NaN, returns 0.

This function does not reduce in the kernel.

πŸ”—opaque
Float.toUInt64 : Float β†’ UInt64

Converts a floating-point number to a 64-bit unsigned integer.

If the given Float is non-negative, truncates the value to a positive integer, rounding down and clamping to the range of UInt64. Returns 0 if the Float is negative or NaN, and returns the largest UInt64 value (i.e. UInt64.size - 1) if the float is larger than it.

This function does not reduce in the kernel.

πŸ”—opaque
Float.toInt64 : Float β†’ Int64

Truncates a floating-point number to the nearest 64-bit signed integer, rounding towards zero.

If the Float is larger than the maximum value for Int64 (including Inf), returns the maximum value of Int64 (i.e. Int64.maxValue). If it is smaller than the minimum value for Int64 (including -Inf), returns the minimum value of Int64 (i.e. Int64.minValue). If it is NaN, returns 0.

This function does not reduce in the kernel.

πŸ”—opaque
Float32.toUInt64 : Float32 β†’ UInt64

Converts a floating-point number to a 64-bit unsigned integer.

If the given Float32 is non-negative, truncates the value to a positive integer, rounding down and clamping to the range of UInt64. Returns 0 if the Float32 is negative or NaN, and returns the largest UInt64 value (i.e. UInt64.size - 1) if the float is larger than it.

This function does not reduce in the kernel.

πŸ”—opaque
Float32.toInt64 : Float32 β†’ Int64

Truncates a floating-point number to the nearest 64-bit signed integer, rounding towards zero.

If the Float is larger than the maximum value for Int64 (including Inf), returns the maximum value of Int64 (i.e. Int64.maxValue). If it is smaller than the minimum value for Int64 (including -Inf), returns the minimum value of Int64 (i.e. Int64.minValue). If it is NaN, returns 0.

This function does not reduce in the kernel.

πŸ”—opaque
Float.toUSize : Float β†’ USize

Converts a floating-point number to a word-sized unsigned integer.

If the given Float is non-negative, truncates the value to a positive integer, rounding down and clamping to the range of USize. Returns 0 if the Float is negative or NaN, and returns the largest USize value (i.e. USize.size - 1) if the float is larger than it.

This function does not reduce in the kernel.

πŸ”—opaque
Float32.toUSize : Float32 β†’ USize

Converts a floating-point number to a word-sized unsigned integer.

If the given Float32 is non-negative, truncates the value to a positive integer, rounding down and clamping to the range of USize. Returns 0 if the Float32 is negative or NaN, and returns the largest USize value (i.e. USize.size - 1) if the float is larger than it.

This function does not reduce in the kernel.

πŸ”—opaque
Float.toISize : Float β†’ ISize

Truncates a floating-point number to the nearest word-sized signed integer, rounding towards zero.

If the Float is larger than the maximum value for ISize (including Inf), returns the maximum value of ISize (i.e. ISize.maxValue). If it is smaller than the minimum value for ISize (including -Inf), returns the minimum value of ISize (i.e. ISize.minValue). If it is NaN, returns 0.

This function does not reduce in the kernel.

πŸ”—opaque
Float32.toISize : Float32 β†’ ISize

Truncates a floating-point number to the nearest word-sized signed integer, rounding towards zero.

If the Float is larger than the maximum value for ISize (including Inf), returns the maximum value of ISize (i.e. ISize.maxValue). If it is smaller than the minimum value for ISize (including -Inf), returns the minimum value of ISize (i.e. ISize.minValue). If it is NaN, returns 0.

This function does not reduce in the kernel.

πŸ”—def
Float.ofInt : Int β†’ Float

Converts an integer into the closest-possible 64-bit floating-point number, or positive or negative infinite floating-point value if the range of Float is exceeded.

πŸ”—def
Float32.ofInt : Int β†’ Float32

Converts an integer into the closest-possible 32-bit floating-point number, or positive or negative infinite floating-point value if the range of Float32 is exceeded.

πŸ”—def
Float.ofNat (n : Nat) : Float

Converts a natural number into the closest-possible 64-bit floating-point number, or an infinite floating-point value if the range of Float is exceeded.

πŸ”—def
Float32.ofNat (n : Nat) : Float32

Converts a natural number into the closest-possible 32-bit floating-point number, or an infinite floating-point value if the range of Float32 is exceeded.

πŸ”—def
Float.ofBinaryScientific (m : Nat) (e : Int) :
  Float

Computes m * 2^e.

πŸ”—def
Float32.ofBinaryScientific (m : Nat) (e : Int) :
  Float32

Computes m * 2^e.

πŸ”—opaque
Float.frExp : Float β†’ Float Γ— Int

Splits the given float x into a significand/exponent pair (s, i) such that x = s * 2^i where s ∈ (-1;-0.5] βˆͺ [0.5; 1). Returns an undefined value if x is not finite.

This function does not reduce in the kernel. It is implemented in compiled code by the C function frexp.

πŸ”—opaque
Float32.frExp : Float32 β†’ Float32 Γ— Int

Splits the given float x into a significand/exponent pair (s, i) such that x = s * 2^i where s ∈ (-1;-0.5] βˆͺ [0.5; 1). Returns an undefined value if x is not finite.

This function does not reduce in the kernel. It is implemented in compiled code by the C function frexp.

18.6.2.4.Β Comparisons

πŸ”—opaque
Float.beq (a b : Float) : Bool

Checks whether two floating-point numbers are equal according to IEEE 754.

Floating-point equality does not correspond with propositional equality. In particular, it is not reflexive since NaN != NaN, and it is not a congruence because 0.0 == -0.0, but 1.0 / 0.0 != 1.0 / -0.0.

This function does not reduce in the kernel. It is compiled to the C equality operator.

πŸ”—opaque
Float32.beq (a b : Float32) : Bool

Checks whether two floating-point numbers are equal according to IEEE 754.

Floating-point equality does not correspond with propositional equality. In particular, it is not reflexive since NaN != NaN, and it is not a congruence because 0.0 == -0.0, but 1.0 / 0.0 != 1.0 / -0.0.

This function does not reduce in the kernel. It is compiled to the C equality operator.

18.6.2.4.1.Β Inequalities

The decision procedures for inequalities are opaque constants in the logic. They can only be used via the Lean.ofReduceBool axiom, e.g. via the native_decide tactic.

πŸ”—def
Float.le : Float β†’ Float β†’ Prop

Non-strict inequality of floating-point numbers. Typically used via the ≀ operator.

πŸ”—def
Float32.le : Float32 β†’ Float32 β†’ Prop

Non-strict inequality of floating-point numbers. Typically used via the ≀ operator.

πŸ”—def
Float.lt : Float β†’ Float β†’ Prop

Strict inequality of floating-point numbers. Typically used via the < operator.

πŸ”—def
Float32.lt : Float32 β†’ Float32 β†’ Prop

Strict inequality of floating-point numbers. Typically used via the < operator.

πŸ”—opaque
Float.decLe (a b : Float) : Decidable (a ≀ b)

Compares two floating point numbers for non-strict inequality.

This function does not reduce in the kernel. It is compiled to the C inequality operator.

πŸ”—opaque
Float32.decLe (a b : Float32) :
  Decidable (a ≀ b)

Compares two floating point numbers for non-strict inequality.

This function does not reduce in the kernel. It is compiled to the C inequality operator.

πŸ”—opaque
Float.decLt (a b : Float) : Decidable (a < b)

Compares two floating point numbers for strict inequality.

This function does not reduce in the kernel. It is compiled to the C inequality operator.

πŸ”—opaque
Float32.decLt (a b : Float32) :
  Decidable (a < b)

Compares two floating point numbers for strict inequality.

This function does not reduce in the kernel. It is compiled to the C inequality operator.

18.6.2.5.Β Arithmetic

Arithmetic operations on floating-point values are typically invoked via the Add Float, Sub Float, Mul Float, Div Float, and HomogeneousPow Float instances, along with the corresponding Float32 instances.

πŸ”—opaque
Float.add : Float β†’ Float β†’ Float

Adds two 64-bit floating-point numbers according to IEEE 754. Typically used via the + operator.

This function does not reduce in the kernel. It is compiled to the C addition operator.

πŸ”—opaque
Float32.add : Float32 β†’ Float32 β†’ Float32

Adds two 32-bit floating-point numbers according to IEEE 754. Typically used via the + operator.

This function does not reduce in the kernel. It is compiled to the C addition operator.

πŸ”—opaque
Float.sub : Float β†’ Float β†’ Float

Subtracts 64-bit floating-point numbers according to IEEE 754. Typically used via the - operator.

This function does not reduce in the kernel. It is compiled to the C subtraction operator.

πŸ”—opaque
Float32.sub : Float32 β†’ Float32 β†’ Float32

Subtracts 32-bit floating-point numbers according to IEEE 754. Typically used via the - operator.

This function does not reduce in the kernel. It is compiled to the C subtraction operator.

πŸ”—opaque
Float.mul : Float β†’ Float β†’ Float

Multiplies 64-bit floating-point numbers according to IEEE 754. Typically used via the * operator.

This function does not reduce in the kernel. It is compiled to the C multiplication operator.

πŸ”—opaque
Float32.mul : Float32 β†’ Float32 β†’ Float32

Multiplies 32-bit floating-point numbers according to IEEE 754. Typically used via the * operator.

This function does not reduce in the kernel. It is compiled to the C multiplication operator.

πŸ”—opaque
Float.div : Float β†’ Float β†’ Float

Divides 64-bit floating-point numbers according to IEEE 754. Typically used via the / operator.

In Lean, division by zero typically yields zero. For Float, it instead yields either Inf, -Inf, or NaN.

This function does not reduce in the kernel. It is compiled to the C division operator.

πŸ”—opaque
Float32.div : Float32 β†’ Float32 β†’ Float32

Divides 32-bit floating-point numbers according to IEEE 754. Typically used via the / operator.

In Lean, division by zero typically yields zero. For Float32, it instead yields either Inf, -Inf, or NaN.

This function does not reduce in the kernel. It is compiled to the C division operator.

πŸ”—opaque
Float.pow : Float β†’ Float β†’ Float

Raises one floating-point number to the power of another. Typically used via the ^ operator.

This function does not reduce in the kernel. It is implemented in compiled code by the C function pow.

πŸ”—opaque
Float32.pow : Float32 β†’ Float32 β†’ Float32

Raises one floating-point number to the power of another. Typically used via the ^ operator.

This function does not reduce in the kernel. It is implemented in compiled code by the C function powf.

πŸ”—opaque
Float.exp (x : Float) : Float

Computes the exponential e^x of a floating-point number.

This function does not reduce in the kernel. It is implemented in compiled code by the C function exp.

πŸ”—opaque
Float32.exp : Float32 β†’ Float32

Computes the exponential e^x of a floating-point number.

This function does not reduce in the kernel. It is implemented in compiled code by the C function expf.

πŸ”—opaque
Float.exp2 (x : Float) : Float

Computes the base-2 exponential 2^x of a floating-point number.

This function does not reduce in the kernel. It is implemented in compiled code by the C function exp2.

πŸ”—opaque
Float32.exp2 : Float32 β†’ Float32

Computes the base-2 exponential 2^x of a floating-point number.

This function does not reduce in the kernel. It is implemented in compiled code by the C function exp2f.

18.6.2.5.1.Β Roots

Computing the square root of a negative number yields NaN.

πŸ”—opaque
Float.sqrt : Float β†’ Float

Computes the square root of a floating-point number.

This function does not reduce in the kernel. It is implemented in compiled code by the C function sqrt.

πŸ”—opaque
Float32.sqrt : Float32 β†’ Float32

Computes the square root of a floating-point number.

This function does not reduce in the kernel. It is implemented in compiled code by the C function sqrtf.

πŸ”—opaque
Float.cbrt : Float β†’ Float

Computes the cube root of a floating-point number.

This function does not reduce in the kernel. It is implemented in compiled code by the C function cbrt.

πŸ”—opaque
Float32.cbrt : Float32 β†’ Float32

Computes the cube root of a floating-point number.

This function does not reduce in the kernel. It is implemented in compiled code by the C function cbrtf.

18.6.2.6.Β Logarithms

πŸ”—opaque
Float.log (x : Float) : Float

Computes the natural logarithm ln x of a floating-point number.

This function does not reduce in the kernel. It is implemented in compiled code by the C function log.

πŸ”—opaque
Float32.log : Float32 β†’ Float32

Computes the natural logarithm ln x of a floating-point number.

This function does not reduce in the kernel. It is implemented in compiled code by the C function logf.

πŸ”—opaque
Float.log10 : Float β†’ Float

Computes the base-10 logarithm of a floating-point number.

This function does not reduce in the kernel. It is implemented in compiled code by the C function log10.

πŸ”—opaque
Float32.log10 : Float32 β†’ Float32

Computes the base-10 logarithm of a floating-point number.

This function does not reduce in the kernel. It is implemented in compiled code by the C function log10f.

πŸ”—opaque
Float.log2 : Float β†’ Float

Computes the base-2 logarithm of a floating-point number.

This function does not reduce in the kernel. It is implemented in compiled code by the C function log2.

πŸ”—opaque
Float32.log2 : Float32 β†’ Float32

Computes the base-2 logarithm of a floating-point number.

This function does not reduce in the kernel. It is implemented in compiled code by the C function log2f.

18.6.2.7.Β Scaling

πŸ”—opaque
Float.scaleB (x : Float) (i : Int) : Float

Efficiently computes x * 2^i.

This function does not reduce in the kernel.

πŸ”—opaque
Float32.scaleB (x : Float32) (i : Int) : Float32

Efficiently computes x * 2^i.

This function does not reduce in the kernel.

18.6.2.8.Β Rounding

πŸ”—opaque
Float.round : Float β†’ Float

Rounds to the nearest integer, rounding away from zero at half-way points.

This function does not reduce in the kernel. It is implemented in compiled code by the C function round.

πŸ”—opaque
Float32.round : Float32 β†’ Float32

Rounds to the nearest integer, rounding away from zero at half-way points.

This function does not reduce in the kernel. It is implemented in compiled code by the C function roundf.

πŸ”—opaque
Float.floor : Float β†’ Float

Computes the floor of a floating-point number, which is the largest integer that's no larger than the given number.

This function does not reduce in the kernel. It is implemented in compiled code by the C function floor.

Examples:

πŸ”—opaque
Float32.floor : Float32 β†’ Float32

Computes the floor of a floating-point number, which is the largest integer that's no larger than the given number.

This function does not reduce in the kernel. It is implemented in compiled code by the C function floorf.

Examples:

πŸ”—opaque
Float.ceil : Float β†’ Float

Computes the ceiling of a floating-point number, which is the smallest integer that's no smaller than the given number.

This function does not reduce in the kernel. It is implemented in compiled code by the C function ceil.

Examples:

πŸ”—opaque
Float32.ceil : Float32 β†’ Float32

Computes the ceiling of a floating-point number, which is the smallest integer that's no smaller than the given number.

This function does not reduce in the kernel. It is implemented in compiled code by the C function ceilf.

Examples:

18.6.2.9.Β Trigonometry

18.6.2.9.1.Β Sine

πŸ”—opaque
Float.sin : Float β†’ Float

Computes the sine of a floating-point number in radians.

This function does not reduce in the kernel. It is implemented in compiled code by the C function sin.

πŸ”—opaque
Float32.sin : Float32 β†’ Float32

Computes the sine of a floating-point number in radians.

This function does not reduce in the kernel. It is implemented in compiled code by the C function sinf.

πŸ”—opaque
Float.sinh : Float β†’ Float

Computes the hyperbolic sine of a floating-point number.

This function does not reduce in the kernel. It is implemented in compiled code by the C function sinh.

πŸ”—opaque
Float32.sinh : Float32 β†’ Float32

Computes the hyperbolic sine of a floating-point number.

This function does not reduce in the kernel. It is implemented in compiled code by the C function sinhf.

πŸ”—opaque
Float.asin : Float β†’ Float

Computes the arc sine (inverse sine) of a floating-point number in radians.

This function does not reduce in the kernel. It is implemented in compiled code by the C function asin.

πŸ”—opaque
Float32.asin : Float32 β†’ Float32

Computes the arc sine (inverse sine) of a floating-point number in radians.

This function does not reduce in the kernel. It is implemented in compiled code by the C function asinf.

πŸ”—opaque
Float.asinh : Float β†’ Float

Computes the hyperbolic arc sine (inverse sine) of a floating-point number.

This function does not reduce in the kernel. It is implemented in compiled code by the C function asinh.

πŸ”—opaque
Float32.asinh : Float32 β†’ Float32

Computes the hyperbolic arc sine (inverse sine) of a floating-point number.

This function does not reduce in the kernel. It is implemented in compiled code by the C function asinhf.

18.6.2.9.2.Β Cosine

πŸ”—opaque
Float.cos : Float β†’ Float

Computes the cosine of a floating-point number in radians.

This function does not reduce in the kernel. It is implemented in compiled code by the C function cos.

πŸ”—opaque
Float32.cos : Float32 β†’ Float32

Computes the cosine of a floating-point number in radians.

This function does not reduce in the kernel. It is implemented in compiled code by the C function cosf.

πŸ”—opaque
Float.cosh : Float β†’ Float

Computes the hyperbolic cosine of a floating-point number.

This function does not reduce in the kernel. It is implemented in compiled code by the C function cosh.

πŸ”—opaque
Float32.cosh : Float32 β†’ Float32

Computes the hyperbolic cosine of a floating-point number.

This function does not reduce in the kernel. It is implemented in compiled code by the C function coshf.

πŸ”—opaque
Float.acos : Float β†’ Float

Computes the arc cosine (inverse cosine) of a floating-point number in radians.

This function does not reduce in the kernel. It is implemented in compiled code by the C function acos.

πŸ”—opaque
Float32.acos : Float32 β†’ Float32

Computes the arc cosine (inverse cosine) of a floating-point number in radians.

This function does not reduce in the kernel. It is implemented in compiled code by the C function acosf.

πŸ”—opaque
Float.acosh : Float β†’ Float

Computes the hyperbolic arc cosine (inverse cosine) of a floating-point number.

This function does not reduce in the kernel. It is implemented in compiled code by the C function acosh.

πŸ”—opaque
Float32.acosh : Float32 β†’ Float32

Computes the hyperbolic arc cosine (inverse cosine) of a floating-point number.

This function does not reduce in the kernel. It is implemented in compiled code by the C function acoshf.

18.6.2.9.3.Β Tangent

πŸ”—opaque
Float.tan : Float β†’ Float

Computes the tangent of a floating-point number in radians.

This function does not reduce in the kernel. It is implemented in compiled code by the C function tan.

πŸ”—opaque
Float32.tan : Float32 β†’ Float32

Computes the tangent of a floating-point number in radians.

This function does not reduce in the kernel. It is implemented in compiled code by the C function tanf.

πŸ”—opaque
Float.tanh : Float β†’ Float

Computes the hyperbolic tangent of a floating-point number.

This function does not reduce in the kernel. It is implemented in compiled code by the C function tanh.

πŸ”—opaque
Float32.tanh : Float32 β†’ Float32

Computes the hyperbolic tangent of a floating-point number.

This function does not reduce in the kernel. It is implemented in compiled code by the C function tanhf.

πŸ”—opaque
Float.atan : Float β†’ Float

Computes the arc tangent (inverse tangent) of a floating-point number in radians.

This function does not reduce in the kernel. It is implemented in compiled code by the C function atan.

πŸ”—opaque
Float32.atan : Float32 β†’ Float32

Computes the arc tangent (inverse tangent) of a floating-point number in radians.

This function does not reduce in the kernel. It is implemented in compiled code by the C function atanf.

πŸ”—opaque
Float.atanh : Float β†’ Float

Computes the hyperbolic arc tangent (inverse tangent) of a floating-point number.

This function does not reduce in the kernel. It is implemented in compiled code by the C function atanh.

πŸ”—opaque
Float32.atanh : Float32 β†’ Float32

Computes the hyperbolic arc tangent (inverse tangent) of a floating-point number.

This function does not reduce in the kernel. It is implemented in compiled code by the C function atanhf.

πŸ”—opaque
Float.atan2 (y x : Float) : Float

Computes the arc tangent (inverse tangent) of y / x in radians, in the range -π–π. The signs of the arguments determine the quadrant of the result.

This function does not reduce in the kernel. It is implemented in compiled code by the C function atan2.

πŸ”—opaque
Float32.atan2 : Float32 β†’ Float32 β†’ Float32

Computes the arc tangent (inverse tangent) of y / x in radians, in the range -π–π. The signs of the arguments determine the quadrant of the result.

This function does not reduce in the kernel. It is implemented in compiled code by the C function atan2f.

18.6.2.10.Β Negation and Absolute Value

πŸ”—opaque
Float.abs : Float β†’ Float

Computes the absolute value of a floating-point number.

This function does not reduce in the kernel. It is implemented in compiled code by the C function fabs.

πŸ”—opaque
Float32.abs : Float32 β†’ Float32

Computes the absolute value of a floating-point number.

This function does not reduce in the kernel. It is implemented in compiled code by the C function fabsf.

πŸ”—opaque
Float.neg : Float β†’ Float

Negates 64-bit floating-point numbers according to IEEE 754. Typically used via the - prefix operator.

This function does not reduce in the kernel. It is compiled to the C negation operator.

πŸ”—opaque
Float32.neg : Float32 β†’ Float32

Negates 32-bit floating-point numbers according to IEEE 754. Typically used via the - prefix operator.

This function does not reduce in the kernel. It is compiled to the C negation operator.