make_SF, add_DF, mul_DF etc.

12 views
Skip to first unread message

Grégory Vanuxem

unread,
Nov 14, 2024, 3:57:17 PM11/14/24
to fricas...@googlegroups.com
Hello,

I was looking at the DoubleFloat domain and its internal
implementation and noticed this:

in src/interp/spad.lisp, it's a small file, at the end:

================================================
;************************************************************************
; SYSTEM COMMANDS
;************************************************************************

(defun |fin| ()
(SETQ *EOF* 'T)
(THROW 'SPAD_READER NIL))

(defun QUOTIENT2 (X Y) (values (TRUNCATE X Y)))

(defun INTEXQUO(X Y)
(multiple-value-bind (quo remv) (TRUNCATE X Y)
(if (= 0 remv) quo nil)))

(defun DIVIDE2 (X Y) (multiple-value-call #'cons (TRUNCATE X Y)))

(defun |makeSF| (mantissa exponent)
(FLOAT (/ mantissa (expt 2 (- exponent))) 0.0d0))

[...]
==================================================

My primary concern is on makeSF which is only used in float.spad to
convert a Float to a DoubleFloat, whereas in src/lisp/primitives.lisp
we have:

==================================================
;; Before version 1.8 Clozure CL had buggy floating point optimizer, so
;; for it we need to omit type declarations to disable optimization
#-(and :openmcl (not :CCL-1.8))
(defmacro DEF_DF_BINOP (name op)
`(defmacro ,name (x y) `(the double-float (,',op (the double-float ,x)
(the double-float ,y)))))
#+(and :openmcl (not :CCL-1.8))
(defmacro DEF_DF_BINOP (name op) `(defmacro ,name (x y) `(,',op ,x ,y)))

(DEF_DF_BINOP |add_DF| +)
(DEF_DF_BINOP |mul_DF| *)
(DEF_DF_BINOP |max_DF| MAX)
(DEF_DF_BINOP |min_DF| MIN)
(DEF_DF_BINOP |sub_DF| -)
(DEF_DF_BINOP |div_DF| /)

[...]
===================================================
So I wonder if makeSF can be renamed to make_DF to use the same naming
scheme and eventually moved to primitives.lisp. In fact maybe other
functions/macros also.

Though?

- Greg

Grégory Vanuxem

unread,
Nov 14, 2024, 4:56:24 PM11/14/24
to fricas...@googlegroups.com
I just found this at the beginning of primitives.lisp, make_DF already
exists and it is used in compiler.boot:

============================================
;;; Making constant doubles
(defun |make_DF|(x e)
(let ((res (read-from-string (format nil "~D.0d~D" x e))))
res)
)

(defmacro |mk_DF|(x e) (|make_DF| x e))
============================================

I don't understand anything anymore :)

- Greg
Reply all
Reply to author
Forward
0 new messages