• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /macosx-10.10.1/emacs-93/emacs/lisp/calc/

Lines Matching +refs:math +refs:integerp

143        (if (> (math-abs n) 100)
146 (list n (math-power-of-2 (math-abs n)))
191 (math-compute-max-digits (math-abs calc-word-size)
197 (defvar math-power-of-2-cache (list 1 2 4 8 16 32 64 128 256 512 1024))
198 (defvar math-big-power-of-2-cache nil)
199 (defun math-power-of-2 (n) ; [I I] [Public]
201 (or (nth n math-power-of-2-cache)
202 (let* ((i (length math-power-of-2-cache))
203 (val (nth (1- i) math-power-of-2-cache)))
205 (setq val (math-mul val 2)
206 math-power-of-2-cache (nconc math-power-of-2-cache
210 (let ((found (assq n math-big-power-of-2-cache)))
213 (let ((po2 (math-ipow 2 n)))
214 (setq math-big-power-of-2-cache
215 (cons (cons n po2) math-big-power-of-2-cache))
218 (defun math-integer-log2 (n) ; [I I] [Public]
220 (p math-power-of-2-cache)
230 (setq val (math-mul val 2))
231 (setq math-power-of-2-cache (nconc math-power-of-2-cache
244 (cond ((Math-messy-integerp w)
245 (calcFunc-and a b (math-trunc w)))
246 ((and w (not (integerp w)))
247 (math-reject-arg w 'fixnump))
248 ((and (integerp a) (integerp b))
249 (math-clip (logand a b) w))
251 (math-binary-modulo-args 'calcFunc-and a b w))
252 ((not (Math-num-integerp a))
253 (math-reject-arg a 'integerp))
254 ((not (Math-num-integerp b))
255 (math-reject-arg b 'integerp))
256 (t (math-clip (cons 'bigpos
257 (math-and-bignum (math-binary-arg a w)
258 (math-binary-arg b w)))
261 (defun math-binary-arg (a w)
262 (if (not (Math-integerp a))
263 (setq a (math-trunc a)))
265 (math-not-bignum (cdr (math-bignum-test (math-sub -1 a)))
266 (math-abs (if w (math-trunc w) calc-word-size)))
269 (defun math-binary-modulo-args (f a b w)
278 (math-reject-arg b "*Inconsistent modulos"))))
281 (if (Math-messy-integerp mod)
282 (setq mod (math-trunc mod))
283 (or (Math-integerp mod)
284 (math-reject-arg mod 'integerp)))
285 (let ((bits (math-integer-log2 mod)))
293 (math-make-mod (if b
298 (defun math-and-bignum (a b) ; [l l l]
300 (let ((qa (math-div-bignum-digit a 512))
301 (qb (math-div-bignum-digit b 512)))
302 (math-mul-bignum-digit (math-and-bignum (math-norm-bignum (car qa))
303 (math-norm-bignum (car qb)))
308 (cond ((Math-messy-integerp w)
309 (calcFunc-or a b (math-trunc w)))
310 ((and w (not (integerp w)))
311 (math-reject-arg w 'fixnump))
312 ((and (integerp a) (integerp b))
313 (math-clip (logior a b) w))
315 (math-binary-modulo-args 'calcFunc-or a b w))
316 ((not (Math-num-integerp a))
317 (math-reject-arg a 'integerp))
318 ((not (Math-num-integerp b))
319 (math-reject-arg b 'integerp))
320 (t (math-clip (cons 'bigpos
321 (math-or-bignum (math-binary-arg a w)
322 (math-binary-arg b w)))
325 (defun math-or-bignum (a b) ; [l l l]
327 (let ((qa (math-div-bignum-digit a 512))
328 (qb (math-div-bignum-digit b 512)))
329 (math-mul-bignum-digit (math-or-bignum (math-norm-bignum (car qa))
330 (math-norm-bignum (car qb)))
335 (cond ((Math-messy-integerp w)
336 (calcFunc-xor a b (math-trunc w)))
337 ((and w (not (integerp w)))
338 (math-reject-arg w 'fixnump))
339 ((and (integerp a) (integerp b))
340 (math-clip (logxor a b) w))
342 (math-binary-modulo-args 'calcFunc-xor a b w))
343 ((not (Math-num-integerp a))
344 (math-reject-arg a 'integerp))
345 ((not (Math-num-integerp b))
346 (math-reject-arg b 'integerp))
347 (t (math-clip (cons 'bigpos
348 (math-xor-bignum (math-binary-arg a w)
349 (math-binary-arg b w)))
352 (defun math-xor-bignum (a b) ; [l l l]
354 (let ((qa (math-div-bignum-digit a 512))
355 (qb (math-div-bignum-digit b 512)))
356 (math-mul-bignum-digit (math-xor-bignum (math-norm-bignum (car qa))
357 (math-norm-bignum (car qb)))
362 (cond ((Math-messy-integerp w)
363 (calcFunc-diff a b (math-trunc w)))
364 ((and w (not (integerp w)))
365 (math-reject-arg w 'fixnump))
366 ((and (integerp a) (integerp b))
367 (math-clip (logand a (lognot b)) w))
369 (math-binary-modulo-args 'calcFunc-diff a b w))
370 ((not (Math-num-integerp a))
371 (math-reject-arg a 'integerp))
372 ((not (Math-num-integerp b))
373 (math-reject-arg b 'integerp))
374 (t (math-clip (cons 'bigpos
375 (math-diff-bignum (math-binary-arg a w)
376 (math-binary-arg b w)))
379 (defun math-diff-bignum (a b) ; [l l l]
381 (let ((qa (math-div-bignum-digit a 512))
382 (qb (math-div-bignum-digit b 512)))
383 (math-mul-bignum-digit (math-diff-bignum (math-norm-bignum (car qa))
384 (math-norm-bignum (car qb)))
389 (cond ((Math-messy-integerp w)
390 (calcFunc-not a (math-trunc w)))
392 (math-binary-modulo-args 'calcFunc-not a nil w))
393 ((and w (not (integerp w)))
394 (math-reject-arg w 'fixnump))
395 ((not (Math-num-integerp a))
396 (math-reject-arg a 'integerp))
398 (math-clip (calcFunc-not a (- w)) w))
399 (t (math-normalize
401 (math-not-bignum (math-binary-arg a w)
404 (defun math-not-bignum (a w) ; [l l]
405 (let ((q (math-div-bignum-digit a 512)))
409 (math-mul-bignum-digit (math-not-bignum (math-norm-bignum (car q))
415 (setq a (math-trunc a)
416 n (if n (math-trunc n) 1))
418 (math-binary-modulo-args 'calcFunc-lsh a n w)
419 (setq w (if w (math-trunc w) calc-word-size))
420 (or (integerp w)
421 (math-reject-arg w 'fixnump))
422 (or (Math-integerp a)
423 (math-reject-arg a 'integerp))
424 (or (Math-integerp n)
425 (math-reject-arg n 'integerp))
427 (math-clip (calcFunc-lsh a n (- w)) w)
429 (setq a (math-clip a w)))
434 (math-quotient (math-clip a w) (math-power-of-2 (- n))))
436 (math-clip (math-mul a (math-power-of-2 n)) w))))))
439 (calcFunc-lsh a (math-neg (or n 1)) w))
445 (setq a (math-trunc a)
446 n (if n (math-trunc n) 1))
448 (math-binary-modulo-args 'calcFunc-ash a n w)
449 (setq w (if w (math-trunc w) calc-word-size))
450 (or (integerp w)
451 (math-reject-arg w 'fixnump))
452 (or (Math-integerp a)
453 (math-reject-arg a 'integerp))
454 (or (Math-integerp n)
455 (math-reject-arg n 'integerp))
457 (math-clip (calcFunc-ash a n (- w)) w)
459 (setq a (math-clip a w)))
460 (let ((two-to-sizem1 (math-power-of-2 (1- w)))
465 (math-add (math-mul two-to-sizem1 2) -1))
466 (t (let ((two-to-n (math-power-of-2 (- n))))
467 (math-add (calcFunc-lsh (math-add two-to-n -1)
472 (calcFunc-ash a (math-neg (or n 1)) w))
475 (setq a (math-trunc a)
476 n (if n (math-trunc n) 1))
478 (math-binary-modulo-args 'calcFunc-rot a n w)
479 (setq w (if w (math-trunc w) calc-word-size))
480 (or (integerp w)
481 (math-reject-arg w 'fixnump))
482 (or (Math-integerp a)
483 (math-reject-arg a 'integerp))
484 (or (Math-integerp n)
485 (math-reject-arg n 'integerp))
487 (math-clip (calcFunc-rot a n (- w)) w)
489 (setq a (math-clip a w)))
492 (calcFunc-rot a (math-mod n w) w))
494 (math-add (calcFunc-lsh a (- n w) w)
497 (defun math-clip (a &optional w) ; [I I] [Public]
498 (cond ((Math-messy-integerp w)
499 (math-clip a (math-trunc w)))
501 (math-binary-modulo-args 'math-clip a nil w))
502 ((and w (not (integerp w)))
503 (math-reject-arg w 'fixnump))
504 ((not (Math-num-integerp a))
505 (math-reject-arg a 'integerp))
507 (setq a (math-clip a (- w)))
508 (if (Math-natnum-lessp a (math-power-of-2 (- -1 w)))
510 (math-sub a (math-power-of-2 (- w)))))
512 (math-normalize (cons 'bigpos (math-binary-arg a w))))
513 ((and (integerp a) (< a 1000000))
518 (math-normalize
520 (math-clip-bignum (cdr (math-bignum-test (math-trunc a)))
523 (defalias 'calcFunc-clip 'math-clip)
525 (defun math-clip-bignum (a w) ; [l l]
526 (let ((q (math-div-bignum-digit a 512)))
530 (math-mul-bignum-digit (math-clip-bignum (math-norm-bignum (car q))
535 (defvar math-max-digits-cache nil)
536 (defun math-compute-max-digits (w r)
538 (res (assq pair math-max-digits-cache)))
542 (digs (math-ceiling (math-div w (math-real-log2 r)))))
543 (setq math-max-digits-cache (cons (cons pair digs)
544 math-max-digits-cache))
547 (defvar math-log2-cache (list '(2 . 1)
553 (defun math-real-log2 (x) ;;; calc-internal-prec must be 6
554 (let ((res (assq x math-log2-cache)))
560 (setq math-log2-cache (cons (cons x log) math-log2-cache))
563 (defconst math-radix-digits ["0" "1" "2" "3" "4" "5" "6" "7" "8" "9"
568 (defsubst math-format-radix-digit (a) ; [X D]
569 (aref math-radix-digits a))
571 (defun math-format-radix (a) ; [X S]
574 (concat "-" (math-format-radix (- a)))
575 (math-format-radix-digit a))
578 (setq s (concat (math-format-radix-digit (% a calc-number-radix)) s)
582 (defconst math-binary-digits ["000" "001" "010" "011"
584 (defun math-format-binary (a) ; [X S]
587 (concat "-" (math-format-binary (- a)))
588 (math-format-radix a))
591 (setq s (concat (aref math-binary-digits (% a 8)) s)
593 (concat (math-format-radix a) s))))
595 (defun math-format-bignum-radix (a) ; [X L]
599 (math-format-radix-digit (car a)))
601 (let ((q (math-div-bignum-digit a calc-number-radix)))
602 (concat (math-format-bignum-radix (math-norm-bignum (car q)))
603 (math-format-radix-digit (cdr q)))))))
605 (defun math-format-bignum-binary (a) ; [X L]
608 (math-format-binary (car a)))
610 (let ((q (math-div-bignum-digit a 512)))
611 (concat (math-format-bignum-binary (math-norm-bignum (car q)))
612 (aref math-binary-digits (/ (cdr q) 64))
613 (aref math-binary-digits (% (/ (cdr q) 8) 8))
614 (aref math-binary-digits (% (cdr q) 8)))))))
616 (defun math-format-bignum-octal (a) ; [X L]
619 (math-format-radix (car a)))
621 (let ((q (math-div-bignum-digit a 512)))
622 (concat (math-format-bignum-octal (math-norm-bignum (car q)))
623 (math-format-radix-digit (/ (cdr q) 64))
624 (math-format-radix-digit (% (/ (cdr q) 8) 8))
625 (math-format-radix-digit (% (cdr q) 8)))))))
627 (defun math-format-bignum-hex (a) ; [X L]
630 (math-format-radix (car a)))
632 (let ((q (math-div-bignum-digit a 256)))
633 (concat (math-format-bignum-hex (math-norm-bignum (car q)))
634 (math-format-radix-digit (/ (cdr q) 16))
635 (math-format-radix-digit (% (cdr q) 16)))))))
639 (defun math-float-parts (a need-frac) ; returns ( int frac fracdigs )
641 (list (math-scale-rounding (nth 1 a) (nth 2 a)) '(float 0 0) 0)
642 (let* ((d (math-numdigs (nth 1 a)))
647 (let ((qr (math-idivmod (nth 1 a) (math-scale-int 1 n))))
648 (list (car qr) (math-make-float (cdr qr) (- n)) n)))
649 (list (math-scale-rounding (nth 1 a) (nth 2 a))
652 (defun math-format-radix-float (a prec)
659 (let* ((afigs (math-abs figs))
660 (fp (math-float-parts a (> afigs 0)))
662 (math-convert-radix-digits
665 (frac (math-round (math-mul (math-normalize (nth 1 fp))
666 (math-radix-float-power afigs)))))
667 (if (not (and (math-zerop frac) (math-zerop int) (< figs 0)))
668 (let ((math-radix-explicit-format nil))
670 (setq str (if (> afigs 0) (math-format-number frac) ""))
676 int (math-add int 1))))
677 (setq str (concat (math-format-number int) point str)))
679 (setq str (math-group-float str))))
686 (1- (math-convert-radix-digits
688 (math-numdigs (nth 1 a)))))))))
689 (calc-internal-prec (+ 3 (math-convert-radix-digits afigs t)))
690 (explo -1) (vlo (math-radix-float-power explo))
691 (exphi 1) (vhi (math-radix-float-power exphi))
693 (setq a (math-normalize a))
696 (if (math-lessp-float '(float 1 0) a)
697 (while (not (math-lessp-float a vhi))
699 exphi (math-mul exphi 2)
700 vhi (math-radix-float-power exphi)))
701 (while (math-lessp-float a vlo)
703 explo (math-mul explo 2)
704 vlo (math-radix-float-power explo))))
705 (while (not (eq (math-sub exphi explo) 1))
706 (setq expmid (math-div2 (math-add explo exphi))
707 vmid (math-radix-float-power expmid))
708 (if (math-lessp-float a vmid)
711 (setq a (math-div-float a vlo)))
712 (let* ((sc (math-round (math-mul a (math-radix-float-power
714 (math-radix-explicit-format nil))
716 (setq str (math-format-number sc))))
721 (math-lessp explo (+ (if (= figs 0)
722 (1- (math-convert-radix-digits
726 (math-lessp calc-display-sci-low explo))
739 (min (math-mod explo 3) (length str))
748 (setq str (math-group-float str)))
752 (math-format-number
753 (math-sub explo eadj)))))
754 (setq str (if (or (memq calc-language '(math maple))
760 (defvar math-radix-digits-cache nil)
762 (defun math-convert-radix-digits (n &optional to-dec)
764 (or (cdr (assoc key math-radix-digits-cache))
766 (log (math-div (math-real-log2 calc-number-radix)
768 (cdr (car (setq math-radix-digits-cache
769 (cons (cons key (math-ceiling (if to-dec
770 (math-mul n log)
771 (math-div n log))))
772 math-radix-digits-cache))))))))
774 (defvar math-radix-float-cache-tag nil)
775 (defvar math-radix-float-cache)
777 (defun math-radix-float-power (n)
780 (or (and (eq calc-number-radix (car math-radix-float-cache-tag))
781 (<= calc-internal-prec (cdr math-radix-float-cache-tag)))
782 (setq math-radix-float-cache-tag (cons calc-number-radix
784 math-radix-float-cache nil))
785 (math-normalize
786 (or (cdr (assoc n math-radix-float-cache))
787 (cdr (car (setq math-radix-float-cache
791 (cdr math-radix-float-cache-tag)))
792 (if (math-negp n)
793 (math-div-float '(float 1 0)
794 (math-radix-float-power
795 (math-neg n)))
796 (math-mul-float (math-sqr-float
797 (math-radix-float-power
798 (math-div2 n)))
799 (if (math-evenp n)
801 (math-float
803 math-radix-float-cache))))))))