master: expt: use (= (ftruncate n) n) to check for integers

stassats via Sbcl-commits <[email protected]>
Newsgroups gmane.lisp.steel-bank.cvs
Message-ID <[email protected]>
The branch "master" has been updated in SBCL:
       via  94b68202423cf0d220c0c690a9b9ae8a554985f7 (commit)
      from  c33aaa910bbff76a97f6347dc2df1b7cd99ac976 (commit)

- Log -----------------------------------------------------------------
commit 94b68202423cf0d220c0c690a9b9ae8a554985f7
Author: Stas Boukarev <[email protected]>
Date:   Sun Aug 30 08:59:42 2026 +0300

    expt: use (= (ftruncate n) n) to check for integers
    
    It's no slower, and can be faster if #+round-float is available.
    It's certainly simpler and more compact.
---
 src/code/irrat.lisp | 47 ++---------------------------------------------
 1 file changed, 2 insertions(+), 45 deletions(-)

diff --git a/src/code/irrat.lisp b/src/code/irrat.lisp
index ea148e5b9..231772b0f 100644
--- a/src/code/irrat.lisp
+++ b/src/code/irrat.lisp
@@ -215,51 +215,8 @@
   "Return BASE raised to the POWER."
   (declare (explicit-check)
            (maybe-inline expt))
-  (labels (;; determine if the double float is an integer
-           #+64-bit
-           (isint (n)
-             (or (zerop n)
-                 (let* ((bits (sb-kernel:double-float-bits n))
-                        (exponent (ldb sb-vm:double-float-exponent-byte bits)))
-                   (cond
-                     ((> exponent (+ sb-vm:double-float-bias sb-vm:double-float-digits)))
-                     ((> exponent sb-vm:double-float-bias)
-                      (not (logtest bits
-                                    (1- (ash 1 (- (+ sb-vm:double-float-bias sb-vm:double-float-digits)
-                                                  exponent))))))))))
-           #-64-bit
-           (isint (x)
-             (or (zerop x)
-                 (let* ((hi (double-float-high-bits x))
-                        (lo (double-float-low-bits x))
-                        (ihi (logand hi #x7fffffff)))
-                   (declare (type (unsigned-byte 31) ihi)
-                            (type (unsigned-byte 32) lo)
-                            (optimize (speed 3) (safety 0)))
-                   (let ((isint 0))
-                     (declare (type fixnum isint))
-                     (cond ((>= ihi #x43400000) ; exponent >= 53
-                            (setq isint 2))
-                           ((>= ihi #x3ff00000)
-                            (let ((k (- (ash ihi -20) #x3ff))) ; exponent
-                              (declare (type (mod 53) k))
-                              (cond ((> k 20)
-                                     (let* ((shift (- 52 k))
-                                            (j (ash lo (- shift)))
-                                            (j2 (ash j shift)))
-                                       (declare (type (mod 32) shift)
-                                                (type (unsigned-byte 32) j j2))
-                                       (when (= j2 lo)
-                                         (setq isint (- 2 (logand j 1))))))
-                                    ((= lo 0)
-                                     (let* ((shift (- 20 k))
-                                            (j (ash ihi (- shift)))
-                                            (j2 (ash j shift)))
-                                       (declare (type (mod 32) shift)
-                                                (type (unsigned-byte 31) j j2))
-                                       (when (= j2 ihi)
-                                         (setq isint (- 2 (logand j 1))))))))))
-                     (/= isint 0)))))
+  (labels ((isint (n)
+             (= (ftruncate n) n))
            (real-expt (x y rtype)
              (let ((x (coerce x 'double-float))
                    (y (coerce y 'double-float)))

-----------------------------------------------------------------------


hooks/post-receive
-- 
SBCL
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.