This is the mail archive of the kawa@sources.redhat.com mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

arithmetic on non-Kawa numbers


I checked in a patch for +, -, and * (but no other operations)
now work on standard Java number classes, such as java.long.Float
and java.math.BigDecimal.

This is quite incomplete, but it's a previews of better Java/Kawa
integration, as dicussed recently (in the context of strings).

The addition does *not* automatically coerce a Java type to a Kawa
type, but instead values are "promoted" according to this hierarchy:

  /** Promotion code for byte/Byte, short/Short, int/Integer. */
  public static final int INT_CODE = 1;
  /** Promotion code for long/Long. */
  public static final int LONG_CODE = 2;
  /** Promotion code for java.math.BigInteger. */
  public static final int BIGINTEGER_CODE = 3;
  /** Promotion code for gnu.math.IntNum. */
  public static final int INTNUM_CODE = 4;
  /** Promotion code for java.math.BigDecimal. */
  public static final int BIGDECIMAL_CODE = 5;
  /** Promotion code for gnu.math.RatNum. */
  public static final int RATNUM_CODE = 6;
  /** Promotion code float/Float. */
  public static final int FLOAT_CODE = 7;
  /** Promotion code double/Double. */
  public static final int DOUBLE_CODE = 8;
  /** Promotion code for gnu.math.FloNum. */
  public static final int FLONUM_CODE = 9;
  /** Promotion code for other gnu.math.Numeric. */
  public static final int NUMERIC_CODE = 10;

For example:
  (+ (java.math.BigInteger:new 12) (java.lang.Short:new 10)
evalues to 22 and is a java.math.BigInteger, wheres:
  (+ (java.math.BigInteger:new 12) (java.lang.Short:new 10) 1000)
evaluates to 1022 and is a Scheme <integer> (gnu.math.IntNum).

A future change would redefine various Kawa types.
Thus a <integer> would still be represented using
<gnu.math.IntNum>, but coercing to <integer> might
be implemented as a call to the new asIntNum method
in gnu.kawa.functions.Arithmetic.  This would allow
BigInteger, Integer, Short, Byte, and Long as well
as IntNum.
--
	--Per Bothner
per@bothner.com   http://per.bothner.com/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]