You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by "Geir Magnusson Jr." <ge...@optonline.net> on 2000/12/27 16:30:09 UTC

template math

I did a little cleanup of the VTL math.  No new functionality was
added.  This notice is really for John's documentation efforts, as well
as for discussion purposes.

This applies to the VTL math found in #set() statements, such as
#set($foo = $bar + 1 )

1) All operations are integer only.  The args are checked to be
integers, and the result is an integer.  If an arg is not an integer,
that is caught, logged, and null returned as the value of the
operation.  (Think of what happens when you want to add a string to an
int :)
2) No longer will it toss an NPE when you use an invalid reference as an
arg on the RHS.
3) Div by 0 is caught for mod (%) and division(/).

On the discussion side, the question will come up is do we do
floating-point math.  I can't see where it's appropos, for what it's
worth.  Some believe that mathematical ops are totally inappropriate for
VTL, but I have used it myself for formatting tables.  (I had an array
of items, and wanted to put N across before starting a new row....)

Thats about it.  Happy Holidays, everyone.

geir

-- 
Geir Magnusson Jr.                               geirm@optonline.com
Velocity : it's not just a good idea. It should be the law.
http://jakarta.apache.org/velocity

Re: template math

Posted by Jon Stevens <jo...@latchkey.com>.
on 12/27/2000 7:30 AM, "Geir Magnusson Jr." <ge...@optonline.net> wrote:

> On the discussion side, the question will come up is do we do
> floating-point math.  I can't see where it's appropos, for what it's
> worth.  Some believe that mathematical ops are totally inappropriate for
> VTL, but I have used it myself for formatting tables.  (I had an array
> of items, and wanted to put N across before starting a new row....)

Right, I think that passing non-integer math back to the Java side of things
is perfectly acceptable. ie:

$math.Floats ("+", "1.002", "2.33")

or something like that to add or multiply (*) floats together.

thanks,

-jon

-- 
Honk if you love peace and quiet.