From 6dedddc545e2f1930bdc2256784eb1551bd4231d Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 1 Feb 2026 00:49:15 +0900 Subject: feat(nuldoc): rewrite nuldoc in Ruby --- .../index.html | 59 ++++++++++++---------- 1 file changed, 31 insertions(+), 28 deletions(-) (limited to 'services/nuldoc/public/blog/posts/2025-10-31/representing-single-value-with-half-open-float-interval/index.html') diff --git a/services/nuldoc/public/blog/posts/2025-10-31/representing-single-value-with-half-open-float-interval/index.html b/services/nuldoc/public/blog/posts/2025-10-31/representing-single-value-with-half-open-float-interval/index.html index 10500010..deff05d3 100644 --- a/services/nuldoc/public/blog/posts/2025-10-31/representing-single-value-with-half-open-float-interval/index.html +++ b/services/nuldoc/public/blog/posts/2025-10-31/representing-single-value-with-half-open-float-interval/index.html @@ -152,8 +152,9 @@ 1p のビット列での表現を見てみよう。

-
1 = 0011111111110000000000000000000000000000000000000000000000000000
-p = 0011111111110000000000000000000000000000000000000000000000000001
+
1 = 0011111111110000000000000000000000000000000000000000000000000000
+p = 0011111111110000000000000000000000000000000000000000000000000001
+

p1 よりも一つ分だけ大きいのがわかるだろうか (ここでは binary64 の具体的な表現について言及していないのでそうなる保証はないのだが、あくまで雰囲気として)。 @@ -182,37 +183,39 @@ binary64 を 64 bit の整数に変換できるなら、他の言語でもほとんど同じ方法で実装できるはずだ。

-
    public static function nextUp(float $x): float
-    {
-        // NaN (Not a Number) なら NaN を返す。
-        if (is_nan($x)) {
-            return NAN;
-        }
-        // 正の無限大なら正の無限大を返す。
-        if (is_infinite($x) && $x > 0) {
-            return INF;
-        }
-        // 0 なら minValue() を返す (後述)。
-        if ($x === 0.0) {
-            return self::minValue();
-        }
-        // binary64 を 64 bit 整数に変換する。
-        $u = self::floatToInt($x);
-        // 正なら整数に +1 して binary64 に戻す。
-        // 負なら整数に -1 して binary64 に戻す。
-        return $x > 0.0 ? self::intToFloat($u + 1) : self::intToFloat($u - 1);
-    }
+
    public static function nextUp(float $x): float
+    {
+        // NaN (Not a Number) なら NaN を返す。
+        if (is_nan($x)) {
+            return NAN;
+        }
+        // 正の無限大なら正の無限大を返す。
+        if (is_infinite($x) && $x > 0) {
+            return INF;
+        }
+        // 0 なら minValue() を返す (後述)。
+        if ($x === 0.0) {
+            return self::minValue();
+        }
+        // binary64 を 64 bit 整数に変換する。
+        $u = self::floatToInt($x);
+        // 正なら整数に +1 して binary64 に戻す。
+        // 負なら整数に -1 して binary64 に戻す。
+        return $x > 0.0 ? self::intToFloat($u + 1) : self::intToFloat($u - 1);
+    }
+

0 のときに返している minValue() は次のような値である。

-
    public static function minValue(): float
-    {
-        // 整数の 1 を binary64 と解釈した値を返す。
-        // binary64 で表せる最小の正の非正規化数。
-        return self::intToFloat(1);
-    }
+
    public static function minValue(): float
+    {
+        // 整数の 1 を binary64 と解釈した値を返す。
+        // binary64 で表せる最小の正の非正規化数。
+        return self::intToFloat(1);
+    }
+
-- cgit v1.3-1-g0d28