=head1 NAME

math.ops - Mathematical Opcodes


=cut

=head1 DESCRIPTION

Operations that perform basic mathematics. See F<src/dynoplibs/> for more
advanced operations.

When making changes to any ops file, run C<make bootstrap-ops> to regenerate
all generated ops files.

=head2 Arithmetic operations

These operations store the results of arithmetic on other registers and
constants into their destination register, $1.

=over 4


=cut

=item B<abs>(inout INT)

=item B<abs>(inout NUM)

=item B<abs>(invar PMC)

Set $1 to its absolute value.

=item B<abs>(out INT, in INT)

=item B<abs>(out NUM, in NUM)

=item B<abs>(out PMC, invar PMC)

Set $1 to absolute value of $2.


=cut

=item B<add>(inout INT, in INT)

=item B<add>(inout NUM, in NUM)

=item B<add>(invar PMC, invar PMC)

=item B<add>(invar PMC, in INT)

=item B<add>(invar PMC, in NUM)

Increase $1 by the amount in $2.

=item B<add>(out INT, in INT, in INT)

=item B<add>(out NUM, in NUM, in NUM)

=item B<add>(invar PMC, invar PMC, invar PMC)

=item B<add>(invar PMC, invar PMC, in INT)

=item B<add>(invar PMC, invar PMC, in NUM)

Set $1 to the sum of $2 and $3.


=cut

=item B<dec>(inout INT)

=item B<dec>(inout NUM)

=item B<dec>(invar PMC)

Decrease $1 by one.


=cut

=item B<div>(inout INT, in INT)

=item B<div>(inout NUM, in NUM)

=item B<div>(invar PMC, invar PMC)

=item B<div>(invar PMC, in INT)

=item B<div>(invar PMC, in NUM)

Divide $1 by $2.

=item B<div>(out INT, in INT, in INT)

=item B<div>(out NUM, in NUM, in NUM)

=item B<div>(invar PMC, invar PMC, invar PMC)

=item B<div>(invar PMC, invar PMC, in INT)

=item B<div>(invar PMC, invar PMC, in NUM)

Set $1 to the quotient of $2 divided by $3. In the case of INTVAL division, the
result is truncated (NOT rounded or floored).
If the denominator is zero, a 'Divide by zero' exception is thrown.


=cut

=item B<fdiv>(inout INT, in INT)

=item B<fdiv>(inout NUM, in NUM)

=item B<fdiv>(invar PMC, invar PMC)

=item B<fdiv>(invar PMC, in INT)

=item B<fdiv>(invar PMC, in NUM)

Floor divide $1 by $2.

=item B<fdiv>(out INT, in INT, in INT)

=item B<fdiv>(out NUM, in NUM, in NUM)

=item B<fdiv>(invar PMC, invar PMC, invar PMC)

=item B<fdiv>(invar PMC, invar PMC, in INT)

=item B<fdiv>(invar PMC, invar PMC, in NUM)

Set $1 to the quotient of $2 divided by $3. The result is the floor()
of the division i.e. the next whole integer towards -inf.
If the denominator is zero, a 'Divide by zero' exception is thrown.


=cut

=item B<ceil>(inout NUM)

Set $1 to the smallest integral value greater than or equal to $1.

=item B<ceil>(out INT, in NUM)

=item B<ceil>(out NUM, in NUM)

Set $1 to the smallest integral value greater than or equal to $2.


=cut

=item B<floor>(inout NUM)

Set $1 to the largest integral value less than or equal to $1.

=item B<floor>(out INT, in NUM)

=item B<floor>(out NUM, in NUM)

Set $1 to the largest integral value less than or equal to $2.


=cut

=item B<inc>(inout INT)

=item B<inc>(inout NUM)

=item B<inc>(invar PMC)

Increase $1 by one.


=cut

=item B<mod>(out INT, in INT, in INT)

=item B<mod>(out NUM, in NUM, in NUM)

=item B<mod>(invar PMC, invar PMC, invar PMC)

=item B<mod>(invar PMC, invar PMC, in INT)

=item B<mod>(invar PMC, invar PMC, in NUM)

Sets $1 to the modulus of $2 and $3.

=item B<mod>(inout INT, in INT)

=item B<mod>(inout NUM, in NUM)

=item B<mod>(invar PMC, invar PMC)

=item B<mod>(invar PMC, in INT)

=item B<mod>(invar PMC, in NUM)

Sets $1 to the modulus of $1 and $2.


NOTE: This "corrected mod" algorithm is based on the C code on page 70
of [1]. Assuming correct behavior of the built-in mod operator (%) with
positive arguments, this algorithm implements a mathematically convenient
version of mod, defined thus:

  x mod y = x - y * floor(x / y)

For more information on this definition of mod, see section 3.4 of [2],
pages 81-85.

References:

  [1] Donald E. Knuth, *MMIXware: A RISC Computer for the Third
      Millennium* Springer, 1999.

  [2] Ronald L. Graham, Donald E. Knuth and Oren Patashnik, *Concrete
      Mathematics*, Second Edition. Addison-Wesley, 1994.


=cut

=item B<mul>(inout INT, in INT)

=item B<mul>(inout NUM, in NUM)

=item B<mul>(invar PMC, invar PMC)

=item B<mul>(invar PMC, in INT)

=item B<mul>(invar PMC, in NUM)

Set $1 to the product of $1 and $2.

=item B<mul>(out INT, in INT, in INT)

=item B<mul>(out NUM, in NUM, in NUM)

=item B<mul>(invar PMC, invar PMC, invar PMC)

=item B<mul>(invar PMC, invar PMC, in INT)

=item B<mul>(invar PMC, invar PMC, in NUM)

Set $1 to the product of $2 and $3.


=cut

=item B<neg>(inout INT)

=item B<neg>(inout NUM)

=item B<neg>(invar PMC)

Set $1 to its negative.

=item B<neg>(out INT, in INT)

=item B<neg>(out NUM, in NUM)

=item B<neg>(out PMC, invar PMC)

Set $1 to the negative of $2.


=cut

=item B<sub>(inout INT, in INT)

=item B<sub>(inout NUM, in NUM)

=item B<sub>(invar PMC, invar PMC)

=item B<sub>(invar PMC, in INT)

=item B<sub>(invar PMC, in NUM)

Decrease $1 by the amount in $2.

=item B<sub>(out INT, in INT, in INT)

=item B<sub>(out NUM, in NUM, in NUM)

=item B<sub>(invar PMC, invar PMC, invar PMC)

=item B<sub>(invar PMC, invar PMC, in INT)

=item B<sub>(invar PMC, invar PMC, in NUM)

Set $1 to $2 minus $3.


=cut

=item B<sqrt>(out NUM, in NUM)

Set $1 to the square root of $2.


=cut

=item B<is_inf_or_nan>(out INT, in NUM)

Set $1 to 1 if $2 is Inf, -Inf or NaN, and 0 otherwise


=cut

=back


=cut

=head1 COPYRIGHT

Copyright (C) 2001-2011, Parrot Foundation.

=head1 LICENSE

This program is free software. It is subject to the same license
as the Parrot interpreter itself.


=cut

