Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use saturating casts in
lean_float_to_uint8
to avoid UB
- Loading branch information
1 parent
9ac4cf9
commit d8c6c82
Showing
3 changed files
with
77 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,53 @@ | ||
|
||
def tst1 : IO Unit := do | ||
IO.println (1 : Float); | ||
IO.println ((1 : Float) + 2); | ||
IO.println ((2 : Float) - 3); | ||
IO.println ((3 : Float) * 2); | ||
IO.println ((3 : Float) / 2); | ||
IO.println (decide ((3 : Float) < 2)); | ||
IO.println (decide ((3 : Float) < 4)); | ||
IO.println ((3 : Float) == 2); | ||
IO.println ((2 : Float) == 2); | ||
IO.println (decide ((3 : Float) ≤ 2)); | ||
IO.println (decide ((3 : Float) ≤ 3)); | ||
IO.println (decide ((3 : Float) ≤ 4)); | ||
IO.println (Float.ofInt 0) | ||
IO.println (Float.ofInt 42) | ||
IO.println (Float.ofInt (-42)) | ||
pure () | ||
IO.println (1 : Float) | ||
IO.println ((1 : Float) + 2) | ||
IO.println ((2 : Float) - 3) | ||
IO.println ((3 : Float) * 2) | ||
IO.println ((3 : Float) / 2) | ||
IO.println (decide ((3 : Float) < 2)) | ||
IO.println (decide ((3 : Float) < 4)) | ||
IO.println ((3 : Float) == 2) | ||
IO.println ((2 : Float) == 2) | ||
IO.println (decide ((3 : Float) ≤ 2)) | ||
IO.println (decide ((3 : Float) ≤ 3)) | ||
IO.println (decide ((3 : Float) ≤ 4)) | ||
IO.println (Float.ofInt 0) | ||
IO.println (Float.ofInt 42) | ||
IO.println (Float.ofInt (-42)) | ||
IO.println (0 / 0 : Float).toUInt8 | ||
IO.println (0 / 0 : Float).toUInt16 | ||
IO.println (0 / 0 : Float).toUInt32 | ||
IO.println (0 / 0 : Float).toUInt64 | ||
IO.println (-1 : Float).toUInt8 | ||
IO.println (256 : Float).toUInt8 | ||
IO.println (1 / 0 : Float).toUInt8 | ||
IO.println (-1 : Float).toUInt64 | ||
IO.println (2^64 : Float).toUInt64 | ||
IO.println (1 / 0 : Float).toUInt64 | ||
|
||
structure Foo := | ||
(x : Nat) | ||
(w : UInt64) | ||
(y : Float) | ||
(z : Float) | ||
structure Foo where | ||
x : Nat | ||
w : UInt64 | ||
y : Float | ||
z : Float | ||
|
||
@[noinline] def mkFoo (x : Nat) : Foo := | ||
{ x := x, w := x.toUInt64, y := x.toFloat / 3, z := x.toFloat / 2 } | ||
{ x := x, w := x.toUInt64, y := x.toFloat / 3, z := x.toFloat / 2 } | ||
|
||
def tst2 (x : Nat) : IO Unit := do | ||
let foo := mkFoo x; | ||
IO.println foo.y; | ||
IO.println foo.z | ||
let foo := mkFoo x | ||
IO.println foo.y | ||
IO.println foo.z | ||
|
||
@[noinline] def fMap (f : Float → Float) (xs : List Float) := | ||
xs.map f | ||
xs.map f | ||
|
||
def tst3 (xs : List Float) (y : Float) : IO Unit := | ||
IO.println (fMap (fun x => x / y) xs) | ||
IO.println (fMap (fun x => x / y) xs) | ||
|
||
def main : IO Unit := do | ||
tst1; | ||
IO.println "-----"; | ||
tst2 7; | ||
tst3 [3, 4, 7, 8, 9, 11] 2; | ||
pure () | ||
tst1 | ||
IO.println "-----" | ||
tst2 7 | ||
tst3 [3, 4, 7, 8, 9, 11] 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters