#11 Simplified BigDecimal support

open
nobody
None
5
2005-07-01
2005-07-01
No

Regarding this:

http://sourceforge.net/mailarchive/forum.php?thread_id=5896978&forum_id=6969

I've slightly modified some source files to support + -
* / > < >= <= == for BigDecimal. Please consider this
is an important enhancement to Loosely Typed Java Syntax.

Attached are the modified files (.java) and the
original files(.java.old from beanshell 2.0b4).

Discussion

  • test.zip: modified files (.java) and the original files(.java.old from beanshell 2.0b4).

     
    Attachments
  • Logged In: YES
    user_id=630205

    Hi, there is a bug on Primitive.java in the modified files.
    BigDecimals were incorrectly promoted with "dobleValue()" as
    value by promotePrimitives causing precision problems.

    The method promotePrimitives must look like this:

    /**
    * Promote the pair of primitives to the maximum type of
    the two. e.g.
    * [int,long]->[long,long]
    */
    static Object[] promotePrimitives(Object lhs, Object rhs)
    {
    lhs = promoteToInteger(lhs);
    rhs = promoteToInteger(rhs);

    if ((lhs instanceof Number) && (rhs instanceof Number))
    {
    Number lnum = (Number) lhs;
    Number rnum = (Number) rhs;

    boolean b;

    if (lnum instanceof BigDecimal || rnum instanceof
    BigDecimal)
    {
    if (lnum instanceof BigDecimal && !(rnum instanceof
    BigDecimal))
    {
    rhs = new BigDecimal(rnum.doubleValue());
    }
    else if (rnum instanceof BigDecimal && !(lnum
    instanceof BigDecimal))
    {
    lhs = new BigDecimal(lnum.doubleValue());
    }
    }
    else if ((b = (lnum instanceof Double)) || (rnum
    instanceof Double))
    {
    if (b)
    rhs = new Double(rnum.doubleValue());
    else
    lhs = new Double(lnum.doubleValue());
    }
    else if ((b = (lnum instanceof Float)) || (rnum
    instanceof Float))
    {
    if (b)
    rhs = new Float(rnum.floatValue());
    else
    lhs = new Float(lnum.floatValue());
    }
    else if ((b = (lnum instanceof Long)) || (rnum
    instanceof Long))
    {
    if (b)
    rhs = new Long(rnum.longValue());
    else
    lhs = new Long(lnum.longValue());
    }
    }

    return new Object[] { lhs, rhs };
    }

     
  •  
    Attachments