Factor Documentation
|
Home
|
Glossary
|
Search
factorcode.org
recip ( x -- y )
Factor documentation
>
Factor handbook
>
The language
>
Numbers
>
Mathematical functions
>
Arithmetic functions
Prev:
neg ( x -- -x )
Next:
conjugate ( z -- z* )
Vocabulary
math
Inputs and outputs
x
a
number
y
a
number
Word description
Computes a number's multiplicative inverse.
Errors
Throws an error if
x
is the integer 0.
Definition
IN:
math
GENERIC:
recip
( x -- y )
Methods
USING:
kernel
math
math.ratios
math.ratios.private
;
M:
integer
recip
1
swap
[
division-by-zero
]
[
dup
0
<
[
[
neg
]
bi@
]
when
fraction>
]
if-zero
;
USING:
kernel
math
;
M:
number
recip
1
swap
/
;
inline
USING:
kernel
math
math.functions
math.ratios.private
;
M:
ratio
recip
>fraction
swap
dup
0
<
[
[
neg
]
bi@
]
when
fraction>
;