Lean ่ฏญ่จ€ๅ‚่€ƒ

20.6.ย ๆตฎ็‚นๆ•ฐ๐Ÿ”—

ๆตฎ็‚นๆ•ฐๆ˜ฏๅœจ่ฎก็ฎ—ๆœบ็กฌไปถไธญๆœ‰ๆ•ˆๅฎž็Žฐ็š„ๅฎžๆ•ฐ็š„่ฟ‘ไผผๅ€ผใ€‚ ไฝฟ็”จๆตฎ็‚นๆ•ฐ็š„่ฎก็ฎ—้žๅธธ้ซ˜ๆ•ˆ๏ผ›็„ถ่€Œ๏ผŒๅฎƒไปฌ่ฟ‘ไผผๅฎžๆ•ฐ็š„ๆ–นๅผ็š„ๆ€ง่ดจๅพˆๅคๆ‚๏ผŒๅญ˜ๅœจ่ฎธๅคšๆž็ซฏๆƒ…ๅ†ตใ€‚ IEEE 754 ๆ ‡ๅ‡†ๅฎšไน‰ไบ†็Žฐไปฃ่ฎก็ฎ—ๆœบไธŠไฝฟ็”จ็š„ๆตฎ็‚นๆ ผๅผ๏ผŒๅ…่ฎธ็กฌไปถ่ฎพ่ฎกไบบๅ‘˜ๅšๅ‡บๆŸไบ›้€‰ๆ‹ฉ๏ผŒ่€Œๅฎž้™…็ณป็ปŸๅœจ่ฟ™ไบ›ๅฐ็ป†่Š‚ไธŠๆœ‰ๆ‰€ไธๅŒใ€‚ ไพ‹ๅฆ‚๏ผŒNaN ๆœ‰่ฎธๅคšไธๅŒ็š„ไฝ่กจ็คบ๏ผŒ็ป“ๆžœๆœชๅฎšไน‰็š„ๆŒ‡็คบ็ฌฆ๏ผŒๅนถไธ”ๆŸไบ›ๅนณๅฐๅœจ้€š่ฟ‡ๆทปๅŠ ไธคไธช NaN ่ฟ”ๅ›ž็š„ NaN ๆ–น้ขๆœ‰ๆ‰€ไธๅŒใ€‚

Lean ๅ…ฌๅผ€ๅบ•ๅฑ‚ๅนณๅฐ็š„ๆตฎ็‚นๅ€ผไปฅไพ›็ผ–็จ‹ไฝฟ็”จ๏ผŒไฝ†ๅฎƒไปฌๆœชๅœจ Lean ็š„้€ป่พ‘ไธญ่ฟ›่กŒ็ผ–็ ใ€‚ ๅฎƒไปฌ็”ฑไธ้€ๆ˜Ž็ฑปๅž‹่กจ็คบใ€‚ ่ฟ™ๆ„ๅ‘ณ็€๏ผŒๅฆ‚ๆžœๆฒกๆœ‰้ขๅค–็š„ ๅ…ฌ็†๏ผŒๅ†…ๆ ธ ๆ— ๆณ•ไฝฟ็”จๆตฎ็‚นๅ€ผ่ฟ›่กŒ่ฎก็ฎ—ๆˆ–ๆŽจ็†ใ€‚ ่ฟ™ๆ ทๅš็š„็ป“ๆžœๆ˜ฏๆตฎ็‚นๆ•ฐ็š„็›ธ็ญ‰ๆ€งๆ˜ฏไธๅฏๅˆคๅฎš็š„ใ€‚ ๆญคๅค–๏ผŒๆตฎ็‚นๅ€ผไน‹้—ด็š„ๆฏ”่พƒๆ˜ฏๅฏๅˆคๅฎš็š„๏ผŒไฝ†่ฟ™ๆ ทๅš็š„ไปฃ็ ๆ˜ฏไธ้€ๆ˜Ž็š„๏ผ›ๅฎž้™…ไธŠ๏ผŒๅ†ณ็ญ–่ฟ‡็จ‹ๅช่ƒฝๅœจ็ผ–่ฏ‘ไปฃ็ ไธญไฝฟ็”จใ€‚

Lean ๆไพ›ไธค็งๆตฎ็‚น็ฑปๅž‹๏ผšFloat ่กจ็คบ 64 ไฝๆตฎ็‚นๅ€ผ๏ผŒ่€Œ Float32 ่กจ็คบ 32 ไฝๆตฎ็‚นๅ€ผใ€‚ Float ็š„็ฒพๅบฆไธไผšๅ›  Lean ่ฟ่กŒ็š„ๅนณๅฐ่€Œๅผ‚ใ€‚

๐Ÿ”—type
Float : 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
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

Leanๅ†…ๆ ธๅฏไปฅๆฏ”่พƒ Float ็ฑปๅž‹็š„่กจ่พพๅผ็š„่ฏญๆณ•็›ธ็ญ‰ๆ€ง๏ผŒๅ› ๆญค 0.0 ๅœจๅฎšไน‰ไธŠ็ญ‰ไบŽๅ…ถ่‡ช่บซใ€‚

example : (0.0 : Float) = (0.0 : Float) := โŠข 0.0 = 0.0 All goals completed! ๐Ÿ™

ๅ†…ๆ ธๆ— ๆณ•ๆฃ€ๆŸฅ้œ€่ฆๅฝ’็บฆๆ‰่ƒฝๅœจ่ฏญๆณ•ไธŠ็›ธ็ญ‰็š„ๆœฏ่ฏญ๏ผš

example : (0.0 : Float) = (0.0 + 0.0 : Float) := โŠข 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โŠข 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

ๅŒๆ ท๏ผŒๅ†…ๆ ธๅœจๆฃ€ๆŸฅ ๅฎšไน‰็ญ‰ไปท ๆ—ถๆ— ๆณ•่ฏ„ไผฐๆตฎ็‚นๆ•ฐ็š„ Bool ๅ€ผๆฏ”่พƒ๏ผš

theorem Float.zero_eq_zero_plus_zero : ((0.0 : Float) == (0.0 + 0.0 : Float)) = 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โŠข (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

ไฝ†ๆ˜ฏ๏ผŒnative_decide็ญ–็•ฅๅฏไปฅ่ฐƒ็”จ Lean ็”จไบŽ่ฟ่กŒๆ—ถ็จ‹ๅบ็š„ๅบ•ๅฑ‚ๅนณๅฐ็š„ๆตฎ็‚นๅŽŸ่ฏญ๏ผš

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! ๐Ÿ™

่ฏฅ็ญ–็•ฅๅฐ†ๅ†ณ็ญ–่ฟ‡็จ‹ไฝœไธบๅทฒ็ผ–่ฏ‘็š„ๆœฌๆœบไปฃ็ ๆ‰ง่กŒใ€‚ ้™คไบ†ๅ†…ๆ ธไน‹ๅค–๏ผŒ่ฟ™่ฟ˜้œ€่ฆไฟกไปป Lean ็ผ–่ฏ‘ๅ™จใ€่งฃ้‡Šๅ™จๅ’Œๅ†…็ฝฎ่ฟ็ฎ—็ฌฆ็š„ไฝŽ็บงๅฎž็Žฐใ€‚ ไธบไบ†็ฒพ็กฎๅœฐ้˜ๆ˜Ž่ฟ™็งไพ่ต–ๆ€ง๏ผŒ็ญ–็•ฅๅˆ›ๅปบไบ†ๅ…ฌ็† Float.zero_eq_zero_plus_zero._native.native_decide.ax_1๏ผš

'Float.zero_eq_zero_plus_zero' depends on axioms: [Classical.choice, Float.zero_eq_zero_plus_zero._native.native_decide.ax_1]#print axioms Float.zero_eq_zero_plus_zero
'Float.zero_eq_zero_plus_zero' depends on axioms: [Classical.choice,
 Float.zero_eq_zero_plus_zero._native.native_decide.ax_1]
Floating-Point Equality Is Not Reflexive

ๆตฎ็‚น่ฟ็ฎ—ๅฏ่ƒฝไผšไบง็”ŸๆŒ‡็คบๆœชๅฎšไน‰็ป“ๆžœ็š„ NaN ๅ€ผใ€‚ ่ฟ™ไบ›ๅ€ผๅฝผๆญคไน‹้—ดๆฒกๆœ‰ๅฏๆฏ”ๆ€ง๏ผ›็‰นๅˆซๆ˜ฏ๏ผŒๆถ‰ๅŠ NaN ็š„ๆ‰€ๆœ‰ๆฏ”่พƒ้ƒฝๅฐ†่ฟ”ๅ›ž false๏ผŒๅŒ…ๆ‹ฌ็›ธ็ญ‰ใ€‚

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

ๅฐ†ๅ‡ฝๆ•ฐๅบ”็”จไบŽไธคไธช็›ธ็ญ‰็š„ๆตฎ็‚นๆ•ฐๅฏ่ƒฝไธไผšไบง็”Ÿ็›ธ็ญ‰็š„ๆ•ฐๅญ—ใ€‚ ็‰นๅˆซๆ˜ฏ๏ผŒๆญฃ้›ถๅ’Œ่ดŸ้›ถๆ˜ฏ้€š่ฟ‡ๆตฎ็‚น็›ธ็ญ‰็›ธ็ญ‰็š„ไธๅŒๅ€ผ๏ผŒไฝ†้™คไปฅๆญฃ้›ถๆˆ–่ดŸ้›ถไผšไบง็”Ÿๆญฃๆ— ็ฉทๅคงๅ€ผๆˆ–่ดŸๆ— ็ฉทๅคงๅ€ผใ€‚

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

20.6.1.ย ๅฅๆณ•๐Ÿ”—

Lean ๆฒกๆœ‰ไธ“็”จ็š„ๆตฎ็‚นๆ–‡ๅญ—ใ€‚ ็›ธๅ๏ผŒๆตฎ็‚นๆ–‡ๅญ—ๆ˜ฏ้€š่ฟ‡ OfScientific ๅ’Œ Neg ็ฑปๅž‹็ฑป็š„้€‚ๅฝ“ๅฎžไพ‹ๆฅ่งฃๆž็š„ใ€‚

Floating-Point Literals

ๆœŸ้™

(-2.523 : Float)

ๆ˜ฏ่ฏญๆณ•็ณ–

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

ๅ’Œๆœฏ่ฏญ

(413.52 : Float32)

ๆ˜ฏ่ฏญๆณ•็ณ–

(OfScientific.ofScientific 41352 true 2 : Float32)

20.6.2.ย API ๅ‚่€ƒ๐Ÿ”—

20.6.2.1.ย ็‰นๆ€ง๐Ÿ”—

ๆตฎ็‚นๆ•ฐๅฑžไบŽไปฅไธ‹ไธ‰็ฑปไน‹ไธ€๏ผš

  • ๆœ‰้™ๆ•ฐๆ˜ฏๆ™ฎ้€š็š„ๆตฎ็‚นๅ€ผใ€‚

  • ๆ— ็ฉทๅคง๏ผˆๅฏไปฅๆ˜ฏๆญฃๆ•ฐๆˆ–่ดŸๆ•ฐ๏ผ‰ๆ˜ฏ้™คไปฅ้›ถ็š„็ป“ๆžœใ€‚

  • NaN ไธๆ˜ฏๆ•ฐๅญ—๏ผŒๆ˜ฏๅ…ถไป–ๆœชๅฎšไน‰่ฟ็ฎ—็š„็ป“ๆžœ๏ผŒไพ‹ๅฆ‚่ดŸๆ•ฐ็š„ๅนณๆ–นๆ นใ€‚

๐Ÿ”—opaque

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

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

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

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

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

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.

20.6.2.2.ย ๅฅๆณ•๐Ÿ”—

่ฟ™ไบ›ๆ“ไฝœ็š„ๅญ˜ๅœจๆ˜ฏไธบไบ†ๆ”ฏๆŒ OfScientific Float ๅ’Œ OfScientific Float32 ๅฎžไพ‹๏ผŒๅนถไธ”้€šๅธธไฝœไธบๆ–‡ๅญ—ๅ€ผ็š„็ป“ๆžœ้—ดๆŽฅ่ฐƒ็”จใ€‚

๐Ÿ”—opaque
Float.ofScientific (m : Nat) (s : Bool) (e : Nat) : Float
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

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.

20.6.2.3.ย ่ฝฌๆข๐Ÿ”—

๐Ÿ”—opaque

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

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

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

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

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

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

This function does not reduce in the kernel.

๐Ÿ”—opaque

Converts a floating-point number to a string.

This function does not reduce in the kernel.

๐Ÿ”—opaque

Converts a floating-point number to a string.

This function does not reduce in the kernel.

๐Ÿ”—opaque

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Computes m * 2^e.

๐Ÿ”—opaque

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

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.

20.6.2.4.ย ๆฏ”่พƒ๐Ÿ”—

๐Ÿ”—opaque
Float.beq (a b : Float) : Bool
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

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.

20.6.2.4.1.ย ไธๅนณ็ญ‰็Žฐ่ฑก๐Ÿ”—

ไธ็ญ‰ๅผ็š„ๅ†ณ็ญ–่ฟ‡็จ‹ๆ˜ฏ้€ป่พ‘ไธญไธ้€ๆ˜Ž็š„ๅธธๆ•ฐใ€‚ ๅฎƒไปฌๅช่ƒฝ้€š่ฟ‡ Lean.ofReduceBool ๅ…ฌ็†ไฝฟ็”จ๏ผŒไพ‹ๅฆ‚้€š่ฟ‡ native_decide็ญ–็•ฅใ€‚

๐Ÿ”—def
Float.le : Float โ†’ Float โ†’ Prop
Float.le : Float โ†’ Float โ†’ Prop

Non-strict inequality of floating-point numbers. Typically used via the โ‰ค operator.

๐Ÿ”—def
Float32.le : Float32 โ†’ Float32 โ†’ Prop
Float32.le : Float32 โ†’ Float32 โ†’ Prop

Non-strict inequality of floating-point numbers. Typically used via the โ‰ค operator.

๐Ÿ”—def
Float.lt : Float โ†’ Float โ†’ Prop
Float.lt : Float โ†’ Float โ†’ Prop

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

๐Ÿ”—def
Float32.lt : Float32 โ†’ Float32 โ†’ Prop
Float32.lt : Float32 โ†’ Float32 โ†’ Prop

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

๐Ÿ”—opaque

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

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

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

Compares two floating point numbers for strict inequality.

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

20.6.2.5.ย ็ฎ—ๆœฏ๐Ÿ”—

ๆตฎ็‚นๅ€ผ็š„็ฎ—ๆœฏ่ฟ็ฎ—้€šๅธธ้€š่ฟ‡ Add Floatใ€Sub Floatใ€Mul Floatใ€Div Float ๅ’Œ HomogeneousPow Float ๅฎžไพ‹ไปฅๅŠ็›ธๅบ”็š„ Float32 ๅฎžไพ‹่ฐƒ็”จใ€‚

๐Ÿ”—opaque
Float.add : Float โ†’ Float โ†’ Float
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

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
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

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
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

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
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

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
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

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

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

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

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

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.

20.6.2.5.1.ย ๆ นๆบ๐Ÿ”—

่ฎก็ฎ—่ดŸๆ•ฐ็š„ๅนณๆ–นๆ นๅพ—ๅˆฐ NaNใ€‚

๐Ÿ”—opaque

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

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

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

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.

20.6.2.6.ย ๅฏนๆ•ฐ๐Ÿ”—

๐Ÿ”—opaque

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

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

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

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

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

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.

20.6.2.7.ย ็ผฉๆ”พ๐Ÿ”—

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

Efficiently computes x * 2^i.

This function does not reduce in the kernel.

๐Ÿ”—opaque

Efficiently computes x * 2^i.

This function does not reduce in the kernel.

20.6.2.8.ย ๅ››่ˆไบ”ๅ…ฅ๐Ÿ”—

๐Ÿ”—opaque

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

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

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

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

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

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:

20.6.2.9.ย ไธ‰่ง’ๅญฆ๐Ÿ”—

20.6.2.9.1.ย ๆญฃๅผฆ๐Ÿ”—

๐Ÿ”—opaque

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

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

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

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

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

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

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

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.

20.6.2.9.2.ย ไฝ™ๅผฆ๐Ÿ”—

๐Ÿ”—opaque

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

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

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

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

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

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

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

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.

20.6.2.9.3.ย ๅˆ‡็บฟ๐Ÿ”—

๐Ÿ”—opaque

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

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

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

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

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

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

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

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

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

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.

20.6.2.10.ย ่ดŸๆ•ฐๅ’Œ็ปๅฏนๅ€ผ๐Ÿ”—

๐Ÿ”—opaque

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

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

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

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.