Node: Efficient Specific Number Functions, Previous: Component Extractions on Numbers, Up: Numbers

Efficient Specific Number Functions

When performing operations on Lpp numbers there is a very small cost in efficiency to dispatch on the types of numbers that are passed as argments to a number function. For example, in the following

     plus(x, y);

the x and y arguments could be two SmallInteger objects, a SmallInteger and a BigInteger object, a BigInteger and a SmallInteger object, a SmallInteger and a Ratio object, a BigInteger and a Ratio object ... etc See Number Types.

This cost, albeit small, can be completely eliminated by casting specific types on the number arguments 1. This can only work when the program knows absolutely what the specific types of numbers are occurring. For example if in a program segment it is absolutely known that only BigInteger objects are occurring then the following

     plus(asThe(BigInteger, x), asThe(BigInteger, y));

would eliminate any dispatching cost.

This situation is rare and it is recommended that the cost is so small in proportion to the algorithms involved that this casting should routinely be avoided; it is simply not worth it.


  1. As of this writing, number functions only dispatch on the specific number types: SmallInteger, BigInteger and Ratio.