Floating point numbers

2 views
Skip to first unread message

Chris Double

unread,
Sep 24, 2007, 9:31:52 PM9/24/07
to The Vodka Language Discussion Group
Are there any workarounds for doing arithmetic on floating point
numbers?

Chris.
--
http://www.bluishcoder.co.nz

tiark...@googlemail.com

unread,
Sep 25, 2007, 5:49:24 PM9/25/07
to The Vodka Language Discussion Group
At the moment, floating point calculations can only be done by
imported Java classes. To work around the current integer-only
limitation, you could write a Java class with some static methods
named plus (one for each combination of parameter types used) and in
Vodka, use the statement

`+` = plus;

to make that method available under the infix operator's name,
overriding the previous one.

At least that's the way I've been planning to implement arithmetic for
the whole numeric hierarchy. Thinking about it again while I'm writing
this, it really seems it shouldn't be too much work, so maybe I'm
gonna find the time to do it in the next days.

- Tiark

tiark...@googlemail.com

unread,
Oct 5, 2007, 8:23:23 PM10/5/07
to The Vodka Language Discussion Group
Hi,

floating-point arithmetic and bit-wise operations on integers should
work now. I have added appropriate methods in
examples/native/VodkaUtil.java, which is loaded automatically
via examples/library/prelude. Please take a look at these files
to see what's implemented exactly.

Note that so far, only 3 + 5, 2.0 + 4.3 and the likes are
supported, but not 3 + 0.5. The reason is that java.lang.Integer
is not a subclass of java.lang.Double, so mixing them in a method
pattern would end up being ambigous. There's an easy workaround,
though:

import native java.lang.Double;

print (doubleValue(3) + 0.5);


BTW, there've been some other changes in the repo, some of
which should provide a little performance improvement.

- Tiark

Reply all
Reply to author
Forward
0 new messages