File tree 1 file changed +5
-2
lines changed
1 file changed +5
-2
lines changed Original file line number Diff line number Diff line change @@ -40,15 +40,16 @@ import Batteries.Data.Rat.Float --#
40
40
41
41
-- `1/10` にはならない!
42
42
/-- info: (3602879701896397 : Rat)/36028797018963968 -/
43
- #guard_msgs in #eval (0 .1 : Float).toRat0
43
+ #guard_msgs in
44
+ #eval (0 .1 : Float).toRat0
44
45
45
46
-- 分母の数は2の冪乗になっている
46
47
-- これは浮動小数点数が内部で2進数で表現されていることを裏付ける
47
48
#guard
48
49
let x := (0 .1 : Float).toRat0.den
49
50
2 ^ Nat.log2 x = x
50
51
51
- /- これでは誤差の存在はわかってもその大きさが分かりづらいので、10進数として正確な表現を出力してみましょう。 -/
52
+ /- これでは誤差の存在はわかってもその大きさが分かりづらいので、10進数として正確な表現を出力してみましょう。[ ^float ] -/
52
53
53
54
/-- 分母が2のベキであるような正の有理数を10進小数として表示する -/
54
55
def Rat.pow2ToBase10Pos (x : Rat) : String :=
@@ -103,3 +104,5 @@ def Float.toExactDecimal (x : Float) : String := x.toRat0.pow2ToBase10
103
104
/-- info: "0.299999999999999988897769753748434595763683319091796875" -/
104
105
#guard_msgs in
105
106
#eval Float.toExactDecimal 0 .3
107
+
108
+ /- [ ^float ] : この浮動小数点数を正確に表示させる関数の実装例は、筆者が Zulip のスレッド "display all of a Float object" で Daniel Weber 氏に教えていただいたものに基づいています。 -/
You can’t perform that action at this time.
0 commit comments