You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by je...@optonline.net on 2005/04/12 01:55:49 UTC

Problem with decimal in most recent snapshot

I am attempting to upgrade from Velocity 1.4 to the 1.5's most recent snapshot.

Basically I am getting a decimal when I should be getting an int with the following code I use in production already:

#set ($colSize = ($jpPop.size() / 3) - 1)
THE COLUMN SIZE IS $colSize


when colSize is printed out it gives a number like 6.3333333 when all values in this calculation are integer.   I should get 6 as an int according to the documentation.

>From what I can see there is no way to make a float an integer either.  This too I would imagine could be a problem.

I was hoping to push this into production tonight but it will have to wait till I can figure out what to do with the potential affects this could have to the whole system or...it gets resolved.

I was hoping to upgrade to help me remove the memory leak as a possible reason why my Tomcat 4.1.30 service is instable and going down with no warnings repeatedly during the day.

JohnE



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


Re: Problem with decimal in most recent snapshot

Posted by Will Glass-Husain <wg...@forio.com>.
Hi,

When you divide two integers it should produce an integer result in 1.5-dev.
Just to confirm - does size() return an int?  (e.g. it's a collection
method).

The decimal patch - while experimental - has been in production on my site 
for over a year.  In general I trust it for production sites.

I'll double-check the division operator.

WILL


----- Original Message ----- 
From: <je...@optonline.net>
To: "Velocity Users List" <ve...@jakarta.apache.org>; "jian chen"
<ch...@gmail.com>
Sent: Monday, April 11, 2005 4:55 PM
Subject: Problem with decimal in most recent snapshot


>I am attempting to upgrade from Velocity 1.4 to the 1.5's most recent
>snapshot.
>
> Basically I am getting a decimal when I should be getting an int with the
> following code I use in production already:
>
> #set ($colSize = ($jpPop.size() / 3) - 1)
> THE COLUMN SIZE IS $colSize
>
>
> when colSize is printed out it gives a number like 6.3333333 when all
> values in this calculation are integer.   I should get 6 as an int
> according to the documentation.
>
> From what I can see there is no way to make a float an integer either.
> This too I would imagine could be a problem.
>
> I was hoping to push this into production tonight but it will have to wait
> till I can figure out what to do with the potential affects this could
> have to the whole system or...it gets resolved.
>
> I was hoping to upgrade to help me remove the memory leak as a possible
> reason why my Tomcat 4.1.30 service is instable and going down with no
> warnings repeatedly during the day.
>
> JohnE
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>


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


Re: Problem with decimal in most recent snapshot

Posted by Will Glass-Husain <wg...@forio.com>.
John,

This is now fixed.  Download the latest source with svn or wait for the 
snapshot download to be updated tonight.

Thanks again for finding this.   Obviously the fault was mine. ;-)

Best,

WILL

----- Original Message ----- 
From: <je...@optonline.net>
To: "Velocity Users List" <ve...@jakarta.apache.org>; "jian chen" 
<ch...@gmail.com>
Sent: Monday, April 11, 2005 4:55 PM
Subject: Problem with decimal in most recent snapshot


>I am attempting to upgrade from Velocity 1.4 to the 1.5's most recent 
>snapshot.
>
> Basically I am getting a decimal when I should be getting an int with the 
> following code I use in production already:
>
> #set ($colSize = ($jpPop.size() / 3) - 1)
> THE COLUMN SIZE IS $colSize
>
>
> when colSize is printed out it gives a number like 6.3333333 when all 
> values in this calculation are integer.   I should get 6 as an int 
> according to the documentation.
>
> From what I can see there is no way to make a float an integer either. 
> This too I would imagine could be a problem.
>
> I was hoping to push this into production tonight but it will have to wait 
> till I can figure out what to do with the potential affects this could 
> have to the whole system or...it gets resolved.
>
> I was hoping to upgrade to help me remove the memory leak as a possible 
> reason why my Tomcat 4.1.30 service is instable and going down with no 
> warnings repeatedly during the day.
>
> JohnE
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> 


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


Re: Problem with decimal in most recent snapshot

Posted by Will Glass-Husain <wg...@forio.com>.
Hi,

Decimal arithmetic in velocity should always returns a decimal - except when
both sides of a division are an integer.  This was agreed upon after a long
long discussion last year.  The basic rationale is backwards compatibility.
The most important use case for this behavior is column arithmetic.  I did
an informal survey of dozens of internal Velocity apps at the time and found
several examples (similar to JohnE's app) where column arithmetic required
integers.

I just tested this and found out that this is not how Velocity is actually
behaving.  Apparently the patch committer went ahead and ignored that
hard-won consensus opinion and slipped in the decimal divided by decimal
equals decimal result.

I'll fix this issue tonight.  Thanks for reporting this.

Best,
WILL

----- Original Message ----- 
From: "Shinobu Kawai" <sh...@gmail.com>
To: "Velocity Users List" <ve...@jakarta.apache.org>
Sent: Monday, April 11, 2005 5:48 PM
Subject: Re: Problem with decimal in most recent snapshot


> Hi JohnE,
>
>> Basically I am getting a decimal when I should be getting an int with the
>> following code I use in production already:
>>
>> #set ($colSize = ($jpPop.size() / 3) - 1)
>> THE COLUMN SIZE IS $colSize
>>
>> when colSize is printed out it gives a number like 6.3333333 when all
>> values in this calculation are integer.   I should get 6 as an int
>> according to the documentation.
>
> The User Guide says:
> "When a division operation is performed between two integers, the
> result will be an integer."
>    http://jakarta.apache.org/velocity/user-guide.html#Math
>
> The MathUtils#divide javadoc says:
> "Integer-types will be returned as Integer-type if and only if the
> modulo of the two numbers is 0."
>
> http://svn.apache.org/repos/asf/jakarta/velocity/trunk/src/java/org/apache/velocity/runtime/parser/node/MathUtils.java
>
> They can't both be right.  If you consider backward compatibility, the
> user guide should be correct.  But my mind says the javadoc is more
> convenient...  Will?
> cf. http://issues.apache.org/bugzilla/show_bug.cgi?id=25874
>
> http://mail-archives.eu.apache.org/mod_mbox/jakarta-velocity-dev/200501.mbox/%3c001201c5081a$68169710$6500a8c0@Apollo%3e
>
>> From what I can see there is no way to make a float an integer either.
>> This too I would imagine could be a problem.
>
> For now, you can use the MathTool.
>
> http://jakarta.apache.org/velocity/tools/generic/MathTool.html#toInteger()
>
>> I was hoping to push this into production tonight but it will have to
>> wait till I can figure out what to do with the potential affects this
>> could have to the whole system or...it gets resolved.
>
> Which, I guess, makes a good reason for the user guide to be right.
>
> Best regards,
> -- Shinobu
>
> --
> Shinobu Kawai <sh...@gmail.com>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>


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


Re: Problem with decimal in most recent snapshot

Posted by Shinobu Kawai <sh...@gmail.com>.
Hi JohnE,

> Basically I am getting a decimal when I should be getting an int with the following code I use in production already:
> 
> #set ($colSize = ($jpPop.size() / 3) - 1)
> THE COLUMN SIZE IS $colSize
> 
> when colSize is printed out it gives a number like 6.3333333 when all values in this calculation are integer.   I should get 6 as an int according to the documentation.

The User Guide says:
"When a division operation is performed between two integers, the
result will be an integer."
    http://jakarta.apache.org/velocity/user-guide.html#Math

The MathUtils#divide javadoc says:
"Integer-types will be returned as Integer-type if and only if the
modulo of the two numbers is 0."
    http://svn.apache.org/repos/asf/jakarta/velocity/trunk/src/java/org/apache/velocity/runtime/parser/node/MathUtils.java

They can't both be right.  If you consider backward compatibility, the
user guide should be correct.  But my mind says the javadoc is more
convenient...  Will?
cf. http://issues.apache.org/bugzilla/show_bug.cgi?id=25874
    http://mail-archives.eu.apache.org/mod_mbox/jakarta-velocity-dev/200501.mbox/%3c001201c5081a$68169710$6500a8c0@Apollo%3e

> From what I can see there is no way to make a float an integer either.  This too I would imagine could be a problem.

For now, you can use the MathTool.
    http://jakarta.apache.org/velocity/tools/generic/MathTool.html#toInteger()

> I was hoping to push this into production tonight but it will have to wait till I can figure out what to do with the potential affects this could have to the whole system or...it gets resolved.

Which, I guess, makes a good reason for the user guide to be right.

Best regards,
-- Shinobu

--
Shinobu Kawai <sh...@gmail.com>

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