velocity-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Geir Magnusson Jr <g...@4quarters.com>
Subject Re: [PATCH] New "Arithmetic Engine"
Date Sat, 03 Jan 2004 13:14:41 GMT

On Jan 2, 2004, at 11:42 PM, Peter Romianowski wrote:

> Hi folks,
>
> finally we got it together - the infamous "decimal number patch" 
> evolved
> and here is the (hopefully) final patch to enable decimal numbers (and
> byte, short, long and BigInteger btw.) in velocity. This patch 
> contains:
>
> - Decimal literals (by Will Glass-Husain)
>    Now you can type things like #set ($foo = 3.14)
> - All arithmetic operations (+ - / *) now work with all Number-types
>    available. Modulo (%) works with all except BigDecimal (there is no
>    such method :)
> - All comparators (< > == != <= >=) work with all Number-types
> - A new type called TemplateNumber (o.a.v.util.TemplateNumber) is
>    available which is treated as a Number in arithmetic operations and
>    comparisons. (by Will Glass-Husain)
>    I am not sure about this one though. But Will had good reasons to
>    implement it - I think I just need some kind of "refreshing" on that
>    ;)
>
> The patch is against the current head (Geir, you gave me a hard time
> during the last days, since you changed the Parser.jjt quite often, so
> that I had to incorporate the changes quite some times ;)

LOL.  The parser change for floats is pretty easy, so if you get out of 
sync, don't worry :)

>
> Additionally some implementation details:
> -----------------------------------------
>
> All aritmetic operations and comparisons are delegated to a new class
> (o.a.v.runtime.parser.MathUtils). All operations are done using
> primitives (as far as possible) and NOT BigInteger / BigDecimal like 
> the
> first proposal did. I added overflow checking all along the way (where
> possible). In addition to that I removed the "paradigm of the smallest
> type" where add (new Integer(1), new Integer(2)) would result in a
> Byte(3). Now types are preserved as far as possible (overflow, mixing 
> of
> types). You find a lot of documentation about that in the javadoc
> (MathUtils.java). Finally, overall, there should be no performance 
> drawback.
> There are also some new testcases and existing ones are updated (mostly
> template based like math.vm).
>
> So we (I hope Will doesn't mind me talking in his name) think this 
> patch
> will increase the usability of velocity a lot and hope that the others
> like it too.
>
> Open for discussion...

I'll apply it and see what happens.

What is 'TemplateNumber'?

What about the remaining issue of

   #set( $ans = 5 / 2 )

I assume we get 2?

geir

>
> Regards
> Peter
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
>
-- 
Geir Magnusson Jr                                   203-247-1713(m)
geir@4quarters.com


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org


Mime
View raw message