数値
type: Function
arguments: * &rest NUMBERS
package: lisp
file: builtin.l
引数を全て乗算した数値を返します。
使用例:
(* 1 2 3)
=> 6
seealso: /
type: Variable
package: lisp
現在の乱数の状態を保持してます。
random が STATE 無しで呼ばれたとき使われます。
seealso: random
seealso: make-random-state
type: Function
arguments: + &rest NUMBERS
package: lisp
file: builtin.l
引数を全て加算して返します。
使用例:
(+ 1 2 3)
=> 6
(+ 1.2 4 -2)
=> 3.2
seealso: -
type: Function
arguments: - NUMBER &rest MORE-NUMBERS
package: lisp
file: builtin.l
引数が一つの場合にはその数値をマイナスにしたものを返します。
引数が二つ以上の場合には一つ目の引数からその他の引数を減算した数値を返します。
使用例:
(- 3)
=> -3
(- 3 2 1)
=> 0
seealso: +
type: Function
arguments: / NUMBER &rest MORE-NUMBERS
package: lisp
file: builtin.l
引数が一つの場合には 1 を引数で除算した数値を返します。
引数が二つ以上の場合には一つ目の引数を二つ目の引数全てで除算した数値を返します。
使用例:
(/ 2)
=> 1/2
(/ 3 2 1)
=> 3/2
(/ 4 3 2)
=> 2/3
seealso: denominator
seealso: numerator
seealso: *
type: Function
arguments: /= NUMBER &rest MORE-NUMBERS
package: lisp
file: builtin.l
引数がすべて異なっていればt、そうでなければnilを返します。
使用例:
(/= 2 3)
=> t
(/= 3 3)
=> nil
(/= 2 3 4 5)
=> t
(/= 2 3 4 2)
=> nil
seealso: =
type: Function
arguments: 1+ NUM
package: lisp
file: number.l
NUMに1を足した数を返します。
使用例:
(1+ 1)
=> 2
seealso: 1-
type: Function
arguments: 1- NUM
package: lisp
file: number.l
NUMから1を引いた数を返します。
使用例:
(1- 2)
=> 1
seealso: 1+
type: Function
arguments: < NUMBER &rest MORE-NUMBERS
package: lisp
file: builtin.l
引数が小さい順に並んでいればt、そうでなければnilを返します。
使用例:
(< 2 3 4)
=> t
(< 2 4 3 5)
=> nil
seealso: >
type: Function
arguments: <= NUMBER &rest MORE-NUMBERS
package: lisp
file: builtin.l
隣り合った引数がすべて<=の関係ならt、そうでなければnilを返します。
使用例:
(<= 2 3 3 4)
=> t
(<= 2 4 3 5)
=> nil
seealso: >=
type: Function
arguments: = NUMBER &rest MORE-NUMBERS
package: lisp
file: builtin.l
引数の数値がすべて等しければt、そうでなければnilを返します。
使用例:
(= 3 3)
=> t
(= 3 4)
=> nil
(= 3 3 3 3)
=> t
(= 3 3 3 4)
=> nil
seealso: equal
seealso: equalp
seealso: /=
type: Function
arguments: > NUMBER &rest MORE-NUMBERS
package: lisp
file: builtin.l
引数が大きい順に並んでいればt、そうでなければnilを返します。
使用例:
(> 3 2 1)
=> t
(> 3 2 1 4)
=> nil
seealso: <
type: Function
arguments: >= NUMBER &rest MORE-NUMBERS
package: lisp
file: builtin.l
隣り合った引数がすべて>=の関係ならt、そうでなければnilを返します。
使用例:
(>= 4 3 3 2 1)
=> t
(>= 4 2 3 1)
=> nil
seealso: <=
type: Function
arguments: abs NUMBER
package: lisp
file: builtin.l
絶対値を返します。
使用例:
;;; 絶対値を返す。
(abs -3.0)
=> 3.0
type: Function
arguments: acos NUMBER
package: lisp
file: builtin.l
逆余弦関数の値を返します。
seealso: acosh
type: Function
arguments: acosh Z
package: lisp
file: number.l
逆双曲線余弦関数を計算します。
seealso: acos
type: Function
arguments: ash INTEGER COUNT
package: lisp
file: builtin.l
整数をロジカルにシフトします。
INTEGER : シフトする数値
COUNT : ビット数分だけ正ならば左に、負ならば右にシフト
例:
;;; 4を左と右に3ビットずつシフトさせてみる。
(ash 4 3)
=> 32
(ash 4 -3)
=> 0
type: Function
arguments: asin NUMBER
package: lisp
file: builtin.l
逆正弦関数の値を返します。
seealso: asinh
type: Function
arguments: asinh Z
package: lisp
file: number.l
逆双曲線正弦関数を計算します。
seealso: asin
type: Function
arguments: atan Y &optional X
package: lisp
file: builtin.l
逆正接関数の値を返します。
seealso: atanh
type: Function
arguments: atanh Z
package: lisp
file: number.l
逆双曲線正接関数を計算します。
seealso: atan
type: Function
arguments: byte SIZE POSITION
package: lisp
file: number.l
byte specifier を作ります。
「0 を基底として POSITION ビット目から始まる SIZE ビット」
を表すオブジェクトを返します。
内部的には cons と同じです。
seealso: dpb
seealso: ldb
seealso: byte-position
seealso: byte-size
type: Function
arguments: byte-position BYTESPEC
package: lisp
file: number.l
byte specifier の位置を返します。
内部的には cdr と同じです。
seealso: byte
type: Function
arguments: byte-size BYTESPEC
package: lisp
file: number.l
byte specifier のサイズを返します。
内部的には car と同じです。
seealso: byte
type: Function
arguments: NUMBER &optional DIVISOR
package: lisp
file: builtin.l
NUMBERを正の無限大方向に丸めます。
DIVISORを省略した場合にはNUMBER以上の最小の整数になります。
使用例:
(ceiling 2.2)
=> 3
(ceiling 2.8)
=> 3
(ceiling -2.2)
=> -2
(multiple-value-list (ceiling 2.2))
=> (3 -0.8)
seealso: floor
seealso: truncate
seealso: round
seealso: fceiling
type: Function
arguments: cis Z
package: lisp
file: number.l
偏角が Z で絶対値が 1 の複素数を返します。
(cis Z) == (complex (cos Z) (sin Z))
type: Function
arguments: complex REALPART &optional IMAGPART
package: lisp
file: builtin.l
指定された実数部(REALPART)と虚数部(IMAGPART)で複素数を表現します。
使用例:
(setq a (complex 0 1))
=>#C(0 1)
(* a a)
=>-1
seealso: imagpart
seealso: realpart
type: Function
arguments: conjugate NUMBER
package: lisp
file: builtin.l
共役複素数を返します。
type: Function
arguments: cos RADIANS
package: lisp
file: builtin.l
余弦関数の値を返します。
type: Function
arguments: cosh Z
package: lisp
file: number.l
双曲線余弦関数を計算します。
type: Macro
arguments: decf PLACE &optional (DELTA 1)
package: lisp
file: setf.l
変数をデクリメントする
使用例:
;;; 変数xの値をデクリメントする。
(setq x 1) => 1
(decf x) => 0
x => 0
seealso: incf
type: Function
arguments: denominator RATIONAL
package: lisp
file: builtin.l
分数の分母を返します。
seealso: numerator
seealso: /
type: Function
arguments: deposit-field NEWBYTE BYTESPEC INTEGER
package: lisp
file: number.l
指定されたフィールドを NEWBYTE の同じフィールドの内容で置き換えた値を返
します。
使用例:
(format nil "~2,'0x" (deposit-field #x0f (byte 4 4) #xa7))
=>"07"
(format nil "~2,'0x" (deposit-field #xaa (byte 4 4) #x0f))
=>"af"
seealso: ldb
seealso: dpb
type: Function
arguments: dpb NEWBYTE BYTESPEC INTEGER
package: lisp
file: number.l
指定されたフィールドを NEWBYTE で置き換えた値を返します。
使用例:
(format nil "~2,'0x" (dpb #x0f (byte 4 4) #xa7))
=>"f7"
(format nil "~2,'0x" (dpb #x0a (byte 4 4) #x0f))
=>"af"
seealso: ldb
seealso: deposit-field
type: Function
arguments: evenp INTEGER
package: lisp
file: builtin.l
INTEGERが偶数ならばt、そうでなければnilを返します。
使用例:
(evenp 2)
=> t
(evenp 0)
=> t
(evenp 1)
=> nil
seealso: oddp
type: Function
arguments: exp NUMBER
package: lisp
file: builtin.l
自然対数の底 e の NUMBER 乗の数値を返します。
使用例:
;;; 自然対数の底 e とその二乗を表示してみる。
(exp 1)
=> 2.718282
(exp 2)
=> 7.389056
type: Function
arguments: expt BASE-NUMBER POWER-NUMBER
package: lisp
file: builtin.l
べき乗します。
使用例:
(expt 2 10)
=> 1024
(expt 10 3)
=> 1000
type: Function
arguments: fceiling NUMBER &optional DIVISOR
package: lisp
file: builtin.l
ceiling と同じですが浮動小数点数を返します。
seealso: ceiling
type: Function
arguments: ffloor NUMBER &optional DIVISOR
package: lisp
file: builtin.l
floor と同じですが浮動小数点数を返します。
seealso: floor
type: Function
arguments: float NUMBER &optional OTHER
package: lisp
file: builtin.l
任意の型の数値を浮動小数点型に変換します。
(float 'NUMBER) == (coerce 'NUMBER 'single-float)
使用例:
;;; integerをfloatに変換する。
(setq var 0) => 0
(type-of var) => integer
(setq var (float var)) => 0.0
(type-of var) => single-float
seealso: rationalize
type: Function
arguments: floor NUMBER &optional DIVISOR
package: lisp
file: builtin.l
NUMBERを負の無限大方向に丸めます。
DIVISORを省略した場合にはNUMBERを越えない最大の整数になります。
使用例:
(floor 2.2)
=> 2
(floor 2.8)
=> 2
(floor -2.4)
=> -3
(multiple-value-list (floor 2.2))
=> (2 0.2)
seealso: ceiling
seealso: truncate
seealso: round
seealso: ffloor
type: Function
arguments: fround NUMBER &optional DIVISOR
package: lisp
file: builtin.l
round と同じですが浮動小数点数を返します。
seealso: round
type: Function
arguments: ftruncate NUMBER &optional DIVISOR
package: lisp
file: builtin.l
truncateと同じですが浮動小数点数を返します。
seealso: truncate
type: Function
arguments: gcd &rest INTEGERS
package: lisp
file: builtin.l
引数の最大公約数を返します。
使用例:
(gcd 91 70)
=> 7
(gcd 63 -42 35)
=> 7
(gcd -3)
=> -3
(gcd 35 8)
=> 1
seealso: lcm
type: Function
arguments: imagpart NUMBER
package: lisp
file: builtin.l
複素数の虚数部を取得します。
使用例:
(setq a (complex 1 3))
=>#C(1 3)
(imagpart a)
=>3
seealso: realpart
seealso: complex
type: Macro
arguments: incf PLACE &optional (DELTA 1)
package: lisp
file: setf.l
変数をインクリメントします。
使用例:
;;; 変数xの値をインクリメントする。
(setq x 1) => 1
(incf x) => 2
x => 2
seealso: decf
type: Function
arguments: integer-length INTEGER
package: lisp
file: builtin.l
2進数で表した時の長さを返します。
使用例:
(integer-length 7) => 3 ; #b00000111
(integer-length 8) => 4 ; #b00001000
type: Function
arguments: isqrt INTEGER
package: lisp
file: builtin.l
整数の平方根を整数で返します。
(isqrt INTEGER) == (floor (sqrt INTEGER))
使用例:
;;; 143と144のisqrtを計算する。
(isqrt 143)
=> 11
(isqrt 144)
=> 12
type: Function
arguments: lcm INTEGER &rest MORE-INTEGERS
package: lisp
file: builtin.l
引数の最小公倍数を返します。
使用例:
(lcm 14 35)
=> 70
(lcm 0 5)
=> 0
(lcm 1 2 3 4 5 6)
=> 60
seealso: gcd
type: Function
arguments: ldb BYTESPEC INTEGER
package: lisp
file: number.l
指定されたフィールドの値を取り出します。
フィールドを指定する byte specifier は関数 byte で作ります。
例:
;;; 最下位ビットを取り出す
(ldb (byte 1 0) #x02) => 0
(ldb (byte 1 0) #x0f) => 1
;;; (最下位バイトの)上位 4 ビットを取り出す
(ldb (byte 4 4) #x0f) => 0
(ldb (byte 4 4) #xaf) => 10
(ldb (byte 4 4) #xf0) => 15
seealso: dpb
seealso: byte
type: Function
arguments: ldb-test BYTESPEC INTEGER
package: lisp
file: number.l
指定されたフィールドが non-zero かどうかを判定します。
(not (zerop (ldb BYTESPEC INTEGER))) と同じです。
seealso: ldb
type: Function
arguments: log NUMBER &optional BASE
package: lisp
file: builtin.l
BASE を底とする NUMBER の対数を返します。
使用例:
(log 2.718282)
=> 1.0
(log 7.389056)
=> 2.0
type: Function
arguments: logand &rest ARGS
package: lisp
file: number.l
ビット毎のANDを取ります。C言語でいう&です。
使用例:
;;; 2進数で#b11110000と#b00110011のビットの積を取る。
(format nil "~8,'0b" (logand #b11110000 #b00110011))
=> "00110000"
seealso: logior
seealso: logandc1
seealso: logandc2
seealso: lognand
seealso: lognot
type: Function
arguments: logandc1 X Y
package: lisp
file: number.l
Xの1の補数 と Y のビット毎の論理積を返します。
使用例:
(format nil "~4,'0b" (logandc1 #b0011 #b0101))
=> "0100"
(format nil "~4,'0b" (logand (lognot #b0011) #b0101))
=> "0100"
seealso: logand
seealso: logandc2
type: Function
arguments: logandc2 X Y
package: lisp
file: number.l
X と Yの1の補数 のビット毎の論理積を返します。
使用例:
(format nil "~4,'0b" (logandc2 #b0011 #b0101))
=> "0010"
(format nil "~4,'0b" (logand #b0011 (lognot #b0101)))
=> "0010"
seealso: logand
seealso: logandc1
type: Function
arguments: logeqv &rest ARGS
package: lisp
file: number.l
ビット毎の論理等価を返します。
使用例:
(format nil "~4,'0b" (logeqv #b0011 #b0101))
=> "-111"
(format nil "~4,'0b" (lognot (logxor #b0011 #b0101)))
=> "-111"
seealso: logxor
type: Function
arguments: logior &rest ARGS
package: lisp
file: number.l
ビット毎のORを取ります。C言語でいう|です。
使用例:
;;; 2進数で#b00110000と#b00000011のビットの和を取る。
(format nil "~8,'0b" (logior #b00110000 #b00000011))
=> "00110011"
seealso: logand
seealso: lognor
seealso: logorc1
seealso: logorc2
type: Function
arguments: lognand X Y
package: lisp
file: number.l
ビット毎の否定的論理積(NAND)を返します。
使用例:
;;; X 0011
;;; Y 0101
;;; AND 0001
;;; NAND 1110
;;; 1の補数 0001
;;; 2の補数 0010
(format nil "~4,'0b" (lognand #b0011 #b0101))
=> "0-10"
(format nil "~4,'0b" (lognot (logand #b0011 #b0101)))
=> "0-10"
seealso: logand
seealso: lognor
type: Function
arguments: lognor X Y
package: lisp
file: number.l
ビット毎の否定的論理和(NOR)を返します。
使用例:
;;; X 0011
;;; Y 0101
;;; OR 0111
;;; NOR 1000
;;; 1の補数 0111
;;; 2の補数 1000
(format nil "~4,'0b" (lognor #b0011 #b0101))
=> "-1000"
(format nil "~4,'0b" (lognot (logior #b0011 #b0101)))
=> "-1000"
seealso: logior
seealso: lognand
type: Function
arguments: lognot INTEGER
package: lisp
file: builtin.l
INTEGERの1の補数(2進数表現で0と1を反転させたもの)を返します。
使用例:
;;; INTEGER 00000011
;;; 反転 11111100
;;; 1の補数 00000011
;;; 2の補数 00000100
(lognot #b0011)
=> -4
(format nil "~8,'0b" -4)
=> "0000-100"
(format nil "~4,'0b" (lognot -4))
=> "0011"
seealso: logand
seealso: logor
type: Function
arguments: logorc1 X Y
package: lisp
file: number.l
Xの1の補数 と Y のビット毎の論理和を返します。
使用例:
(format nil "~4,'0B" (logorc1 #b0011 #b0101))
=> "0-11"
(format nil "~4,'0b" (logior (lognot #b0011) #b0101))
=> "0-11"
seealso: logior
seealso: logorc2
type: Function
arguments: logorc2 X Y
package: lisp
file: number.l
X と Yの1の補数 のビット毎の論理和を返します。
使用例:
(format nil "~4,'0B" (logorc2 #b0011 #b0101))
=> "-101"
(format nil "~4,'0b" (logior #b0011 (lognot #b0101)))
=> "-101"
seealso: logior
seealso: logorc1
type: Function
arguments: logxor &rest ARGS
package: lisp
file: number.l
ビット毎の排他的論理和を返します。
使用例:
(format nil "~4,'0b" (logxor #b0011 #b0101))
=> "0110"
seealso: logeqv
type: Function
arguments: make-random-state &optional STATE
package: lisp
file: builtin.l
乱数の状態を初期化します
STATE:
nil 初期化はせずに現在の*random-state*のコピーを返します。
t 時刻に基づいて新しい状態を作ります。
random-state この関数(make-random-state)の戻り値を渡すとコピーが返ります。
使用例:
;;;乱数列の再現
(let ((rs1 (make-random-state nil))
(rs2 (make-random-state nil))) ;;現状の乱数状態のコピーを二つ作る
(dotimes (i 10)
(format t "~A " (random 100 rs1))) ;;一つ目
(terpri)
(dotimes (i 10)
(format t "~A " (random 100 rs1))) ;;一つ目やりすぎて
(terpri)
(dotimes (i 10)
(format t "~A " (random 100 rs2))) ;;二つ目を少し見てみる。
(terpri))
=>3 41 81 70 73 66 32 72 2 55 ;ここと
21 97 83 14 86 26 99 69 18 46
3 41 81 70 73 66 32 72 2 55 ;ここが同じになる
seealso: *random-state*
seealso: random-state-p
seealso: random
type: Function
arguments: mask-field BYTESPEC INTEGER
package: lisp
file: number.l
指定されたフィールド以外を 0 とした値を返します。
;; ldb との比較
(format nil "~2,'0x" (ldb (byte 4 4) #xaf))
=>"0a"
(format nil "~2,'0x" (mask-field (byte 4 4) #xaf))
=>"a0"
seealso: ldb
type: Function
arguments: max NUMBER &rest MORE-NUMBERS
package: lisp
file: builtin.l
引数の中で最大の数値を返します。
使用例:
(max 3)
=> 3
(max -3 0 2)
=> 2
(max 2.5 1)
=> 2.5
(max 3 2.5)
=> 3
seealso: min
type: Function
arguments: min NUMBER &rest MORE-NUMBERS
package: lisp
file: builtin.l
引数の中で最小の数値を返します。
使用例:
(min 3)
=> 3
(min -2 0 3)
=> -2
(min 2.5 1)
=> 1
seealso: max
type: Function
arguments: minusp NUMBER
package: lisp
file: builtin.l
NUMBER がゼロより小さければ t 、そうでなければ nil を返します。
使用例:
(minusp 0)
=> nil
(minusp -1)
=> t
(minusp -0.00001)
=> t
seealso: plusp
type: Function
arguments: mod NUMBER DIVISOR
package: lisp
file: builtin.l
(floor NUMBER DIVISOR)の戻り値の二つ目を返します。
使用例:
(mod 13 4)
=> 1
(mod -13 4)
=> 3
seealso: floor
seealso: rem
type: Function
arguments: numerator RATIONAL
package: lisp
file: builtin.l
分数の分子を返します。
seealso: denominator
seealso: /
type: Function
arguments: oddp INTEGER
package: lisp
file: builtin.l
INTEGERが奇数ならばt、そうでなければnilを返します。
使用例:
(oddp 1)
=> t
(oddp 0)
=> nil
(oddp -35)
=> t
seealso: evenp
type: Function
arguments: phase Z
package: lisp
file: number.l
複素数の偏角を求めます。
戻り値はラジアン単位です。
(phase -1)
=>3.141593
type: Function
arguments: plusp NUMBER
package: lisp
file: builtin.l
NUMBERがゼロより大きければt、そうでなければnilを返します。
使用例:
(plusp 0)
=> nil
(plusp 1)
=> t
(plusp 0.00001)
=> t
seealso: minusp
type: Function
arguments: random NUMBER &optional STATE
file: builtin.l
0以上NUMBER未満の乱数を返します。
STATE: 乱数の状態変数です。破壊的に処理されます。
seealso: *random-state*
seealso: make-random-state
type: Function
arguments: rational NUMBER
package: lisp
file: builtin.l
実数を有理数に変換します。もしも、 NUMBER がすでに有理数だったら、そのま
ま返します。 rational の場合は、浮動小数点数を全く誤差を含まないものとし
て扱い、その浮動小数点数を数学的に有理数化します。
;;; 0.5 は2進数でちょうど表せる
(rational 0.5)
=>1/2
;;; 0.1 は2進数では誤差を含む
(rational 0.1)
=>13421773/134217728
;;; 倍精度だとまた違う
(rational 0.1d0)
=>3602879701896397/36028797018963968
seealso: rationalize
type: Function
arguments: rationalize NUMBER
package: lisp
file: builtin.l
実数を有理数に変換します。もしも、 NUMBER がすでに有理数だったら、そのま
ま返します。 rationalize の場合は、浮動小数点数を表示される範囲までの精
度で扱い、近似して有理数化します。
seealso: rational
seealso: float
type: Function
arguments: realpart NUMBER
package: lisp
file: builtin.l
複素数の実数部を取得します。
使用例:
(setq a (complex 1 3))
=>#C(1 3)
(realpart a)
=>1
seealso: imagpart
seealso: complex
type: Function
arguments: rem NUMBER DIVISOR
package: lisp
file: builtin.l
(truncate NUMBER DIVISOR)の戻り値の二つ目を返します。
使用例:
(rem 13 4)
=> 1
(rem -13 4)
=> -1
seealso: truncate
seealso: mod
type: Function
arguments: NUMBER &optional DIVISOR
package: lisp
file: builtin.l
NUMBERを近い方の整数に丸めます。
ちょうど0.5の場合には偶数方向に丸められます。
使用例:
(round 2.5)
=> 2
(round 2.6)
=> 3
(round 3.5)
=> 4
(round -2.5)
=> -2
(round -2.6)
=> -3
(multiple-value-list (round 2.5))
=> (2 0.5)
seealso: floor
seealso: ceiling
seealso: truncate
seealso: fround
type: Function
arguments: signum NUMBER
package: lisp
file: builtin.l
数値の符号を返します。
引数が複素数の場合は偏角が等しく絶対値が 1 の複素数を返します
使用例:
(signum 12)
=> 1
(signum 0)
=> 0
(signum -5.0)
=>-1.0
(signum (complex 1 1))
=>#C(0.7071068 0.7071068)
type: Function
arguments: sin RADIANS
package: lisp
file: builtin.l
正弦関数の値を返します。
type: Function
arguments: sinh Z
package: lisp
file: number.l
双曲線正弦関数を計算します。
type: Function
arguments: sqrt NUMBER
package: lisp
file: builtin.l
平方根の値を返します。
type: Function
arguments: tan RADIANS
package: lisp
file: builtin.l
正接関数の値を返します。
type: Function
arguments: tanh Z
package: lisp
file: number.l
双曲線正接関数を計算します。
type: Function
arguments: truncate NUMBER &optional DIVISOR
package: lisp
file: builtin.l
NUMBERを0の方向に丸めます。
使用例:
(truncate 2.8)
=> 2
(truncate -2.8)
=> -2
(multiple-value-list (truncate 2.8))
=> (2 0.8)
seealso: rem
seealso: floor
seealso: ceiling
seealso: round
seealso: ftruncate
type: Function
arguments: zerop NUMBER
package: lisp
file: builtin.l
NUMBERがゼロならt、そうでなければnilを返します。
使用例:
(zerop 0)
=> t
(zerop 1)
=> nil
(zerop 0.0)
=> t
(zerop -0.00)
=> t