You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Paul Lynch <pl...@gmail.com> on 2006/08/08 19:39:55 UTC

Status of floating point literals and arithmetic?

I just ran into a case where I wanted to do something like the following in
a template:

#set($fontSize1Percent = 85)
#set($fontSize2Percent = 0.75 * $fontSize1Percent)

When this didn't parse, I searched the velocity mail archives for
information on floating points, and found the the lengthy 2002 discussion.
The impression I got was that there was some interest in adding the ability
to specify floating point literals and to allow floating point arithmetic.
Was anything actually checked in for it?  (As I recall the 1.4 release came
out quite a while after 2002.)  If not, is the current best practice for
this sort of thing to use the MathTool class in the GenericTools
sub-project?  With that, I could do something like:

#set($fontSize1Percent = 85)
#set($reduction = $math.div(75, 100))
#set($fontSize2Percent = $math.mul($reduction, $fontSize1Percent))

Thanks,
       --Paul Lynch

Re: Status of floating point literals and arithmetic?

Posted by Nathan Bubna <nb...@gmail.com>.
Floating point arithmetic has been added to the
very-stable-but-as-yet-not-released Velocity 1.5-dev version.  If you
check out the SVN head, you can build and use it.

For previous versions of Velocity, i would recommend MathTool. :)

On 8/8/06, Paul Lynch <pl...@gmail.com> wrote:
> I just ran into a case where I wanted to do something like the following in
> a template:
>
> #set($fontSize1Percent = 85)
> #set($fontSize2Percent = 0.75 * $fontSize1Percent)
>
> When this didn't parse, I searched the velocity mail archives for
> information on floating points, and found the the lengthy 2002 discussion.
> The impression I got was that there was some interest in adding the ability
> to specify floating point literals and to allow floating point arithmetic.
> Was anything actually checked in for it?  (As I recall the 1.4 release came
> out quite a while after 2002.)  If not, is the current best practice for
> this sort of thing to use the MathTool class in the GenericTools
> sub-project?  With that, I could do something like:
>
> #set($fontSize1Percent = 85)
> #set($reduction = $math.div(75, 100))
> #set($fontSize2Percent = $math.mul($reduction, $fontSize1Percent))
>
> Thanks,
>        --Paul Lynch
>
>

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


Re: Status of floating point literals and arithmetic?

Posted by Paul Lynch <pl...@gmail.com>.
That's an excellent suggestion, which I hadn't considered-- as long as you
do the multiplication first, it should work fine.

Unfortunately, my real problem is a little more complicated, so I can't do
it that way.  I'll probably just use MathUtil, but I'll try to keep your
suggestion in mind-- it may come in handy for something later.
   --Paul

On 8/8/06, Gonzalo Diethelm <go...@diethelm.org> wrote:
>
> I would just do:
>
> #set ($fontSize1Percent = 85)
> #set ($fontSize2Percent = $fontSize1Percent * 75 / 100)
>
> although I admit it is a cop out... Regards.
>
> On Tue, 2006-08-08 at 13:39 -0400, Paul Lynch wrote:
>
> > I just ran into a case where I wanted to do something like the following
> in
> > a template:
> >
> > #set($fontSize1Percent = 85)
> > #set($fontSize2Percent = 0.75 * $fontSize1Percent)
> >
> > When this didn't parse, I searched the velocity mail archives for
> > information on floating points, and found the the lengthy 2002
> discussion.
> > The impression I got was that there was some interest in adding the
> ability
> > to specify floating point literals and to allow floating point
> arithmetic.
> > Was anything actually checked in for it?  (As I recall the 1.4 release
> came
> > out quite a while after 2002.)  If not, is the current best practice for
> > this sort of thing to use the MathTool class in the GenericTools
> > sub-project?  With that, I could do something like:
> >
> > #set($fontSize1Percent = 85)
> > #set($reduction = $math.div(75, 100))
> > #set($fontSize2Percent = $math.mul($reduction, $fontSize1Percent))
> >
> > Thanks,
> >        --Paul Lynch
>
>
> --
> Gonzalo Diethelm
> gonzalo.diethelm@aditiva.com
>
>

Re: Status of floating point literals and arithmetic?

Posted by Gonzalo Diethelm <go...@diethelm.org>.
I would just do:

#set ($fontSize1Percent = 85)
#set ($fontSize2Percent = $fontSize1Percent * 75 / 100)

although I admit it is a cop out... Regards.

On Tue, 2006-08-08 at 13:39 -0400, Paul Lynch wrote:

> I just ran into a case where I wanted to do something like the following in
> a template:
> 
> #set($fontSize1Percent = 85)
> #set($fontSize2Percent = 0.75 * $fontSize1Percent)
> 
> When this didn't parse, I searched the velocity mail archives for
> information on floating points, and found the the lengthy 2002 discussion.
> The impression I got was that there was some interest in adding the ability
> to specify floating point literals and to allow floating point arithmetic.
> Was anything actually checked in for it?  (As I recall the 1.4 release came
> out quite a while after 2002.)  If not, is the current best practice for
> this sort of thing to use the MathTool class in the GenericTools
> sub-project?  With that, I could do something like:
> 
> #set($fontSize1Percent = 85)
> #set($reduction = $math.div(75, 100))
> #set($fontSize2Percent = $math.mul($reduction, $fontSize1Percent))
> 
> Thanks,
>        --Paul Lynch


-- 
Gonzalo Diethelm
gonzalo.diethelm@aditiva.com