Kawa can generally do a pretty good job of generating efficient code for numeric operations, at least when it knows or can figure out the types of the operands.
The basic operations
are compiled to single-instruction bytecode if both
Likewise, if both operands are floating-point (or
one is floating-point and the other is rational),
instructions are emitted.
A binary operation involving an infinite-precision
and a fixed-size
long is normally
evaluated by expanding the latter to
integer arithmetic. An exception is
an integer literal whose
value fits in an
long - in that case
the operation is done using
In general, integer literals have amorphous type.
When used to infer the type of a variable, they have
(let ((v1 0)) ... v1 has type integer ... )
However, a literal whose value fits in the
is implicitly viewed
long in certain contexts,
primarily method overload resolution and binary arithmetic
(as mentioned above).
The comparison functions
=> are also optimized to single instriction
operations if the operands have appropriate type.
However, the functions
have not yet been optimized.
(positive? x) write
(> x 0).
There are a number of integer division and modulo operations.
If the operands are
long, it is faster
If you know the first operand is non-negative and the second is positive,
(If an operand is an arbitrary-precision
then it dosn’t really matter.)
The logical operations
bitwise-arithmetic-shift-right are compiled
to single bitcode instructions if the operands are
bitwise-arithmetic-shift if the sign of the shift is known.
If the operands are arbitrary-precision
a library call is needed, but run-time type dispatch is avoided.