Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Arbitrary precision binary float class

Reply
Thread Tools

Arbitrary precision binary float class

 
 
Thinkit
Guest
Posts: n/a
 
      12-19-2003
OK, I'm working on an arbitrary precision binary floating point class.
It's modeled somewhat similar to IBM's BigDecimal replacement, but
it's in binary. I got the standard 4 functions, plus a compareTo in
there. Anything else I should add?
 
Reply With Quote
 
 
 
 
Thinkit
Guest
Posts: n/a
 
      12-20-2003
(Thinkit) wrote in message news:<. com>...
> OK, I'm working on an arbitrary precision binary floating point class.
> It's modeled somewhat similar to IBM's BigDecimal replacement, but
> it's in binary. I got the standard 4 functions, plus a compareTo in
> there. Anything else I should add?


Decimal conversions are out of the question.
 
Reply With Quote
 
 
 
 
Lee Fesperman
Guest
Posts: n/a
 
      12-21-2003
Thinkit wrote:
>
> (Thinkit) wrote in message news:<. com>...
> > OK, I'm working on an arbitrary precision binary floating point class.
> > It's modeled somewhat similar to IBM's BigDecimal replacement, but
> > it's in binary. I got the standard 4 functions, plus a compareTo in
> > there. Anything else I should add?

>
> Decimal conversions are out of the question.


Too hard for you?

--
Lee Fesperman, FirstSQL, Inc. (http://www.firstsql.com)
================================================== ============
* The Ultimate DBMS is here!
* FirstSQL/J Object/Relational DBMS (http://www.firstsql.com)
 
Reply With Quote
 
Thomas Schodt
Guest
Posts: n/a
 
      12-21-2003
(Thinkit) wrote in
news: om:

> (Thinkit) wrote in message
> news:<. com>...
>> OK, I'm working on an arbitrary precision binary floating point
>> class.
>> It's modeled somewhat similar to IBM's BigDecimal replacement, but
>> it's in binary. I got the standard 4 functions, plus a compareTo in
>> there. Anything else I should add?

>
> Decimal conversions are out of the question.


Amusing, the first two methods I thought of;


Constructor that lets you create a BigBinary
from a String in any base (up to 36)

BigBinary BigBinary.Binary(String s,int radix);


toString() method that allows you to get the value of
a BigBinary in any base (up to 36)

String BigBinary.toString(int radix);


Conversion between radix is missing from BigDecimal, so I wrote my own.
There are probably other that did the same, it is not that difficult.

PI in hex: 3.243f6a8885a308d313198a2e03707344a4093822299f
(from 50-odd decimal accuracy).
 
Reply With Quote
 
Thinkit
Guest
Posts: n/a
 
      12-22-2003
Thomas Schodt <news0310@xenoc.$DEMON.co.uk> wrote in message news:<Xns945898E9B5916xenoc@158.152.254.254>...
> (Thinkit) wrote in
> news: om:
>
> > (Thinkit) wrote in message
> > news:<. com>...
> >> OK, I'm working on an arbitrary precision binary floating point
> >> class.
> >> It's modeled somewhat similar to IBM's BigDecimal replacement, but
> >> it's in binary. I got the standard 4 functions, plus a compareTo in
> >> there. Anything else I should add?

> >
> > Decimal conversions are out of the question.

>
> Amusing, the first two methods I thought of;
>
>
> Constructor that lets you create a BigBinary
> from a String in any base (up to 36)
>
> BigBinary BigBinary.Binary(String s,int radix);
>
>
> toString() method that allows you to get the value of
> a BigBinary in any base (up to 36)
>
> String BigBinary.toString(int radix);
>
>
> Conversion between radix is missing from BigDecimal, so I wrote my own.
> There are probably other that did the same, it is not that difficult.
>
> PI in hex: 3.243f6a8885a308d313198a2e03707344a4093822299f
> (from 50-odd decimal accuracy).


Hey, BigBinary, good idea. I have it as BinaryFloat now. I could do
those, but I'd have to exclude the number comprised of the first and
third primes multiplied as I think it is repulsive. Give an error
announcing that the source code is Evil.

So is radix manipulation with floating point standardized? I think
there's no way you can avoid loss of accuracy, but perhaps you can
make that loss more consistent.
 
Reply With Quote
 
Thomas Schodt
Guest
Posts: n/a
 
      12-22-2003
(Thinkit) wrote in
news: om:

> Hey, BigBinary, good idea. I have it as BinaryFloat now. I could do
> those, but I'd have to exclude the number comprised of the first and
> third primes multiplied as I think it is repulsive. Give an error
> announcing that the source code is Evil.


Would you be interested in providing a rational explanation for this
seemingly arbitrary animosity?


> So is radix manipulation with floating point standardized?


Regular float/double are binary entities, check IEEE 754.
They are only given a decimal representation in toString().

It follows that they can be given a representation in
any radix - the first one that comes to mind is binary.


> I think there's no way you can avoid loss of accuracy,
> but perhaps you can make that loss more consistent.


The precision of IEEE 754 entities is well defined (consistent),
for float it is 24 bits, for double it is 53 bits.
 
Reply With Quote
 
Thinkit
Guest
Posts: n/a
 
      12-22-2003
Thomas Schodt <news0310@xenoc.$DEMON.co.uk> wrote in message news:<Xns94596C1F4B416xenoc@158.152.254.254>...
> (Thinkit) wrote in
> news: om:


> > So is radix manipulation with floating point standardized?

>
> Regular float/double are binary entities, check IEEE 754.
> They are only given a decimal representation in toString().
>
> It follows that they can be given a representation in
> any radix - the first one that comes to mind is binary.
>
>
> > I think there's no way you can avoid loss of accuracy,
> > but perhaps you can make that loss more consistent.

>
> The precision of IEEE 754 entities is well defined (consistent),
> for float it is 24 bits, for double it is 53 bits.


One of the reasons I wanted to do it in software is that you can get
over-precision errors due to the implementation in hardware. The
hardware uses a double extended with something like 50h bits of total
precision (in the x86). Now some other hardware might do exactly the
standard 40h bit double, in which case you can get an inconsistency.

I haven't thought much about arbitrary radix i/o to binary. Is it
especially complicated? Since I don't care about speed, I would like
something short and understandable. But why limit it to base 24h?
Why not each digit in hexadecimal (of course) with commas since a
digit may be more than one hexit.
 
Reply With Quote
 
Thomas Schodt
Guest
Posts: n/a
 
      12-22-2003
(Thinkit) wrote in
news: om:

> One of the reasons I wanted to do it in software is that you can get
> over-precision errors due to the implementation in hardware.


Have you checked if strictfp might do what you want?

http://makeashorterlink.com/?G3E741FD6
http://www.jguru.com/faq/view.jsp?EID=17544
http://makeashorterlink.com/?N20832FD6

> I haven't thought much about arbitrary radix i/o to binary. Is it
> especially complicated? Since I don't care about speed, I would like
> something short and understandable. But why limit it to base 24h?


java.util.BigInteger supports radix 2 through 36,
representing numbers with "digits" 0..9 and A..Z,
seems to have been sufficient so far.
 
Reply With Quote
 
Thinkit
Guest
Posts: n/a
 
      12-24-2003
Thomas Schodt <news0310@xenoc.$DEMON.co.uk> wrote in message news:<Xns945898E9B5916xenoc@158.152.254.254>...
> (Thinkit) wrote in
> news: om:
>
> > (Thinkit) wrote in message
> > news:<. com>...
> >> OK, I'm working on an arbitrary precision binary floating point
> >> class.
> >> It's modeled somewhat similar to IBM's BigDecimal replacement, but
> >> it's in binary. I got the standard 4 functions, plus a compareTo in
> >> there. Anything else I should add?

> >
> > Decimal conversions are out of the question.

>
> Amusing, the first two methods I thought of;
>
>
> Constructor that lets you create a BigBinary
> from a String in any base (up to 36)
>
> BigBinary BigBinary.Binary(String s,int radix);
>
>
> toString() method that allows you to get the value of
> a BigBinary in any base (up to 36)
>
> String BigBinary.toString(int radix);
>
>
> Conversion between radix is missing from BigDecimal, so I wrote my own.
> There are probably other that did the same, it is not that difficult.
>
> PI in hex: 3.243f6a8885a308d313198a2e03707344a4093822299f
> (from 50-odd decimal accuracy).


Well I'll go ahead and put it in for any integer radix. One thing
I've noticed is it's hard to find arbitrary radix conversions for
floating point binaries (usually the IEEE ones). Is it complicated,
or just very slow if you choose to do it in a straightforward manner?
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Float precision and float equality Anton81 Python 26 12-11-2009 08:37 AM
float to string to float, with first float == second float Carsten Fuchs C++ 45 10-08-2009 09:47 AM
Heap overflow/corruption problem in an arbitrary precision class Martin the Third C++ 8 06-13-2008 07:47 PM
Selectable precision binary float class? Thinkit Java 2 11-28-2003 09:47 PM
Re: float->byte->float is same with original float image. why float->ubyte->float is different??? bd C Programming 0 07-07-2003 12:09 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57