You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by Peter Romianowski <an...@gmx.de> on 2003/10/24 11:27:50 UTC

Floating point (oh no - not again! ;)

Hi,

first of all: Geir, good to see you back again! That makes me hope
that something is happening again.

To the beloved floating point stuff:

In the beginning of this summer the whole floating point stuff got
rolling. Some people (me included and mostly Will Glass-Husain)
discussed about the implementation details. What we have until now:

- My (old) Numbers-Patch
- Will's decimal literals
- many ideas ;)

I'd like to put it all together (including a nicer implementation
of my original patch), but there are still some things to solve.

The biggest one is how do we invoke methods that have numbers
(int or floating point) as arguments. Say we have a method like
this:

public void foo (int value);

Since we can try to invoke it with a Long, a Byte, a Float ... what
shall we do? Do we want to include "silent" parameter conversion?
Or do we want to stick to a strict type model so that we can only
invoke that method with an Integer? But what do we do, if the
user does something like that:

ctx.put ("lv", new Long(3));
ctx.put ("iv", new Integer(3));

#set ($value = $lv+$iv)

The current proposal would result in $value being a Long with the
value 3. It is a Long since we found in discussion that converting
to the smallest type (would be byte) is not feasable. But then we
cannot call our 'foo'-method.

I could imagine something like:

1. Try to find a method with a signature that matches our paramter-set.
2. If 1. is unsuccessful then go through all similar methods where we
    could substitute the Number-values.

Say we have the following methods:

public void foo (int a, String s)
public void foo (double a, String s)

If we try to invoke foo (new Long(100), "test") then we could call
foo (new Long(100).intValue(), "test") since 100 could be represented
as an Integer as well. Invoking foo (new Long(Integer.MAX_VALUE+1), "test")
would result in an error since the value cannot be represented as an
Integer or we would invokie foo ((new Long(Integer.MAX_VALUE+1).doubleValue(),
"test") which I would not prefer.

Another suggestion would be to leave it up to the template-designer. That
way a template-designer would have to write:

$obj.foo($myLong.intValue(), "test")

That would make writing templates a bit more sophisticated for developers
with no programming background. One could imagine a cast-syntax too (I would
not ;) like:

$foo((int)$myLong, "test")

Uaaahhhh - not really... ;)


This "what method to invoke"-problem is the last to solve before we can have
a (really) working proposal on floating point (and Long, Byte btw!).

Waiting for your comments ;)


Regards,
Peter













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


Re: Floating point

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

Had a chance to investigate BeanUtils.  No help there; if there's multiple
properties with the same name but different args, it just returns the first
one in the list.  (Acceptable in that case as the JavaBeans spec states you
shouldn't overload the property setters).

My opinion remains that it'd be easier to implement a strict match to
Integer, but more useful if we could do some type of silent parameter
conversion.

WILL

----- Original Message ----- 
From: "Will Glass-Husain" <wg...@forio.com>
To: "Velocity Developers List" <ve...@jakarta.apache.org>
Sent: Friday, October 24, 2003 8:15 AM
Subject: Re: Floating point


> Hi Peter,
>
> Nice to see things rolling again.  I have some time next week to help.
> Let's not forget the TemplateNumber idea too, I thought that was pretty
> useful.
>
> My thought is to be liberal.
>
> (1) If there's an exact match for the arg type, (e.g. long arg, long
value)
> take it.
> (2) Match the closest type, perhaps by referring to a static lookup table.
>
> What does the commons BeanUtils do?  That might be a good model to follow.
> (Although it also converts Strings, which we don't want to do).
>
> WILL
>
> ----- Original Message ----- 
> From: "Peter Romianowski" <an...@gmx.de>
> To: "Velocity Developers List" <ve...@jakarta.apache.org>
> Sent: Friday, October 24, 2003 2:27 AM
> Subject: Floating point (oh no - not again! ;)
>
>
> > Hi,
> >
> > first of all: Geir, good to see you back again! That makes me hope
> > that something is happening again.
> >
> > To the beloved floating point stuff:
> >
> > In the beginning of this summer the whole floating point stuff got
> > rolling. Some people (me included and mostly Will Glass-Husain)
> > discussed about the implementation details. What we have until now:
> >
> > - My (old) Numbers-Patch
> > - Will's decimal literals
> > - many ideas ;)
> >
> > I'd like to put it all together (including a nicer implementation
> > of my original patch), but there are still some things to solve.
> >
> > The biggest one is how do we invoke methods that have numbers
> > (int or floating point) as arguments. Say we have a method like
> > this:
> >
> > public void foo (int value);
> >
> > Since we can try to invoke it with a Long, a Byte, a Float ... what
> > shall we do? Do we want to include "silent" parameter conversion?
> > Or do we want to stick to a strict type model so that we can only
> > invoke that method with an Integer? But what do we do, if the
> > user does something like that:
> >
> > ctx.put ("lv", new Long(3));
> > ctx.put ("iv", new Integer(3));
> >
> > #set ($value = $lv+$iv)
> >
> > The current proposal would result in $value being a Long with the
> > value 3. It is a Long since we found in discussion that converting
> > to the smallest type (would be byte) is not feasable. But then we
> > cannot call our 'foo'-method.
> >
> > I could imagine something like:
> >
> > 1. Try to find a method with a signature that matches our paramter-set.
> > 2. If 1. is unsuccessful then go through all similar methods where we
> >     could substitute the Number-values.
> >
> > Say we have the following methods:
> >
> > public void foo (int a, String s)
> > public void foo (double a, String s)
> >
> > If we try to invoke foo (new Long(100), "test") then we could call
> > foo (new Long(100).intValue(), "test") since 100 could be represented
> > as an Integer as well. Invoking foo (new Long(Integer.MAX_VALUE+1),
> "test")
> > would result in an error since the value cannot be represented as an
> > Integer or we would invokie foo ((new
> Long(Integer.MAX_VALUE+1).doubleValue(),
> > "test") which I would not prefer.
> >
> > Another suggestion would be to leave it up to the template-designer.
That
> > way a template-designer would have to write:
> >
> > $obj.foo($myLong.intValue(), "test")
> >
> > That would make writing templates a bit more sophisticated for
developers
> > with no programming background. One could imagine a cast-syntax too (I
> would
> > not ;) like:
> >
> > $foo((int)$myLong, "test")
> >
> > Uaaahhhh - not really... ;)
> >
> >
> > This "what method to invoke"-problem is the last to solve before we can
> have
> > a (really) working proposal on floating point (and Long, Byte btw!).
> >
> > Waiting for your comments ;)
> >
> >
> > Regards,
> > Peter
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
>


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


Re: Floating point

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

Nice to see things rolling again.  I have some time next week to help.
Let's not forget the TemplateNumber idea too, I thought that was pretty
useful.

My thought is to be liberal.

(1) If there's an exact match for the arg type, (e.g. long arg, long value)
take it.
(2) Match the closest type, perhaps by referring to a static lookup table.

What does the commons BeanUtils do?  That might be a good model to follow.
(Although it also converts Strings, which we don't want to do).

WILL

----- Original Message ----- 
From: "Peter Romianowski" <an...@gmx.de>
To: "Velocity Developers List" <ve...@jakarta.apache.org>
Sent: Friday, October 24, 2003 2:27 AM
Subject: Floating point (oh no - not again! ;)


> Hi,
>
> first of all: Geir, good to see you back again! That makes me hope
> that something is happening again.
>
> To the beloved floating point stuff:
>
> In the beginning of this summer the whole floating point stuff got
> rolling. Some people (me included and mostly Will Glass-Husain)
> discussed about the implementation details. What we have until now:
>
> - My (old) Numbers-Patch
> - Will's decimal literals
> - many ideas ;)
>
> I'd like to put it all together (including a nicer implementation
> of my original patch), but there are still some things to solve.
>
> The biggest one is how do we invoke methods that have numbers
> (int or floating point) as arguments. Say we have a method like
> this:
>
> public void foo (int value);
>
> Since we can try to invoke it with a Long, a Byte, a Float ... what
> shall we do? Do we want to include "silent" parameter conversion?
> Or do we want to stick to a strict type model so that we can only
> invoke that method with an Integer? But what do we do, if the
> user does something like that:
>
> ctx.put ("lv", new Long(3));
> ctx.put ("iv", new Integer(3));
>
> #set ($value = $lv+$iv)
>
> The current proposal would result in $value being a Long with the
> value 3. It is a Long since we found in discussion that converting
> to the smallest type (would be byte) is not feasable. But then we
> cannot call our 'foo'-method.
>
> I could imagine something like:
>
> 1. Try to find a method with a signature that matches our paramter-set.
> 2. If 1. is unsuccessful then go through all similar methods where we
>     could substitute the Number-values.
>
> Say we have the following methods:
>
> public void foo (int a, String s)
> public void foo (double a, String s)
>
> If we try to invoke foo (new Long(100), "test") then we could call
> foo (new Long(100).intValue(), "test") since 100 could be represented
> as an Integer as well. Invoking foo (new Long(Integer.MAX_VALUE+1),
"test")
> would result in an error since the value cannot be represented as an
> Integer or we would invokie foo ((new
Long(Integer.MAX_VALUE+1).doubleValue(),
> "test") which I would not prefer.
>
> Another suggestion would be to leave it up to the template-designer. That
> way a template-designer would have to write:
>
> $obj.foo($myLong.intValue(), "test")
>
> That would make writing templates a bit more sophisticated for developers
> with no programming background. One could imagine a cast-syntax too (I
would
> not ;) like:
>
> $foo((int)$myLong, "test")
>
> Uaaahhhh - not really... ;)
>
>
> This "what method to invoke"-problem is the last to solve before we can
have
> a (really) working proposal on floating point (and Long, Byte btw!).
>
> Waiting for your comments ;)
>
>
> Regards,
> Peter
>
>
>
>
>
>
>
>
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
>


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