create procedure lib_math_mod (
                     val_dividend bigint,
                     val_divisor bigint)
                   returns (
                     val_mod bigint)
  as
    begin
      /*
        calculate modulo of division
      */

      if (   (val_dividend is null)
          or (val_divisor is null))
        then
          val_mod = null;
        else
          val_mod = val_dividend - ((val_dividend / val_divisor) * val_divisor);

      suspend;
    end