Skip to content

Commit 076b9cc

Browse files
authored
Merge pull request #1344 from lean-ja/Seasawher/issue1330
Floatのコード例の出所を明示する
2 parents 79bab49 + 5cd5a1b commit 076b9cc

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

LeanByExample/Type/Float.lean

+5-2
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,16 @@ import Batteries.Data.Rat.Float --#
4040

4141
-- `1/10` にはならない!
4242
/-- info: (3602879701896397 : Rat)/36028797018963968 -/
43-
#guard_msgs in #eval (0.1 : Float).toRat0
43+
#guard_msgs in
44+
#eval (0.1 : Float).toRat0
4445

4546
-- 分母の数は2の冪乗になっている
4647
-- これは浮動小数点数が内部で2進数で表現されていることを裏付ける
4748
#guard
4849
let x := (0.1 : Float).toRat0.den
4950
2 ^ Nat.log2 x = x
5051

51-
/- これでは誤差の存在はわかってもその大きさが分かりづらいので、10進数として正確な表現を出力してみましょう。 -/
52+
/- これでは誤差の存在はわかってもその大きさが分かりづらいので、10進数として正確な表現を出力してみましょう。[^float] -/
5253

5354
/-- 分母が2のベキであるような正の有理数を10進小数として表示する -/
5455
def Rat.pow2ToBase10Pos (x : Rat) : String :=
@@ -103,3 +104,5 @@ def Float.toExactDecimal (x : Float) : String := x.toRat0.pow2ToBase10
103104
/-- info: "0.299999999999999988897769753748434595763683319091796875" -/
104105
#guard_msgs in
105106
#eval Float.toExactDecimal 0.3
107+
108+
/- [^float]: この浮動小数点数を正確に表示させる関数の実装例は、筆者が Zulip のスレッド "display all of a Float object" で Daniel Weber 氏に教えていただいたものに基づいています。 -/

0 commit comments

Comments
 (0)