Handbook
Glossary
factorcode.org
/mod ( x y -- z w )
Factor handbook
»
The language
»
Numbers
»
Arithmetic
»
Modular arithmetic
Prev:
rem ( x y -- z )
Next:
/i ( x y -- z )
Vocabulary
math
Inputs
x
a
real
y
a
real
Outputs
z
an
integer
w
a
real
Word description
Computes the quotient
z
and remainder
w
of dividing
x
by
y
, with the remainder being negative if
x
is negative.
•
The quotient of two fixnums may overflow and yield a bignum; the remainder is always a fixnum
•
The quotient and remainder of two bignums is always a bignum.
Examples
USING: kernel math prettyprint ; 5 3 /mod [ . ] bi@
1 2
USING: kernel math prettyprint ; 5/2 1/3 /mod [ . ] bi@
7 1/6
See also
Division by zero
Definition
IN:
math
MATH:
/mod
( x y -- z w )
foldable
flushable
Methods
USING:
math
math.private
;
M:
bignum
/mod
bignum/mod
;
inline
USING:
math
math.private
;
M:
fixnum
/mod
fixnum/mod
;
inline
USING:
kernel
math
math.ratios.private
;
M:
ratio
/mod
scale+d
[
/mod
]
[
/
]
bi*
;
USING:
kernel
math
;
M:
real
/mod
2dup
mod
[
swap
[
-
]
[
/i
]
bi*
]
keep
;
inline