Function: cl-float-limits

cl-float-limits is an autoloaded and byte-compiled function defined in cl-extra.el.gz.

Signature

(cl-float-limits)

Documentation

Initialize the Common Lisp floating-point parameters.

This sets the values of: cl-most-positive-float, cl-most-negative-float, cl-least-positive-float, cl-least-negative-float, cl-float-epsilon, cl-float-negative-epsilon, cl-least-positive-normalized-float, and cl-least-negative-normalized-float.

View in manual

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/cl-extra.el.gz
;;;###autoload
(defun cl-float-limits ()
  "Initialize the Common Lisp floating-point parameters.
This sets the values of: `cl-most-positive-float', `cl-most-negative-float',
`cl-least-positive-float', `cl-least-negative-float', `cl-float-epsilon',
`cl-float-negative-epsilon', `cl-least-positive-normalized-float', and
`cl-least-negative-normalized-float'."
  (or cl-most-positive-float (not (numberp '2e1))
      (let ((x '2e0) y z)
	;; Find maximum exponent (first two loops are optimizations)
	(while (cl--finite-do '* x x) (setq x (* x x)))
	(while (cl--finite-do '* x (/ x 2)) (setq x (* x (/ x 2))))
	(while (cl--finite-do '+ x x) (setq x (+ x x)))
	(setq z x y (/ x 2))
	;; Now cl-fill in 1's in the mantissa.
	(while (and (cl--finite-do '+ x y) (/= (+ x y) x))
	  (setq x (+ x y) y (/ y 2)))
	(setq cl-most-positive-float x
	      cl-most-negative-float (- x))
	;; Divide down until mantissa starts rounding.
	(setq x (/ x z) y (/ 16 z) x (* x y))
	(while (condition-case _ (and (= x (* (/ x 2) 2)) (> (/ y 2) 0))
		 (arith-error nil))
	  (setq x (/ x 2) y (/ y 2)))
	(setq cl-least-positive-normalized-float y
	      cl-least-negative-normalized-float (- y))
	;; Divide down until value underflows to zero.
	(setq x (/ z) y x)
	(while (condition-case _ (> (/ x 2) 0) (arith-error nil))
	  (setq x (/ x 2)))
	(setq cl-least-positive-float x
	      cl-least-negative-float (- x))
	(setq x '1e0)
	(while (/= (+ '1e0 x) '1e0) (setq x (/ x 2)))
	(setq cl-float-epsilon (* x 2))
	(setq x '1e0)
	(while (/= (- '1e0 x) '1e0) (setq x (/ x 2)))
	(setq cl-float-negative-epsilon (* x 2))))
  nil)