# LISP - 數字

Common Lisp定義了幾種數字。數字數據類型包括由LISP支持各種數字。

• Integers

• Ratios

• Floating-yiibai numbers

• Complex numbers

## 在LISP各種數值類型

Data type

fixnum

bignum

ratio

float

complex

(write (/ 1 2)) (terpri) (write ( + (/ 1 2) (/ 3 4))) (terpri) (write ( + #c( 1 2) #c( 3 -4)))

1/2 5/4 #C(4 -2)

## 數字函數

Function

+, -, *, /

sin, cos, tan, acos, asin, atan

sinh, cosh, tanh, acosh, asinh, atanh

exp

expt

sqrt

log

conjugate

abs

gcd

lcm

isqrt

floor, ceiling, truncate, round

ffloor, fceiling, ftruncate, fround

mod, rem

float

rational, rationalize

numerator, denominator

realpart, imagpart

(write (/ 45 78)) (terpri) (write (floor 45 78)) (terpri) (write (/ 3456 75)) (terpri) (write (floor 3456 75)) (terpri) (write (ceiling 3456 75)) (terpri) (write (truncate 3456 75)) (terpri) (write (round 3456 75)) (terpri) (write (ffloor 3456 75)) (terpri) (write (fceiling 3456 75)) (terpri) (write (ftruncate 3456 75)) (terpri) (write (fround 3456 75)) (terpri) (write (mod 3456 75)) (terpri) (setq c (complex 6 7)) (write c) (terpri) (write (complex 5 -9)) (terpri) (write (realpart c)) (terpri) (write (imagpart c))

15/26 0 1152/25 46 47 46 46 46.0 47.0 46.0 46.0 6 #C(6 7) #C(5 -9) 6 7