Arbitrary precision binary float class

T

Thinkit

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?
 
T

Thinkit

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.
 
T

Thomas Schodt

(e-mail address removed) (Thinkit) wrote in
(e-mail address removed) (Thinkit) wrote in message


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).
 
T

Thinkit

Thomas Schodt said:
(e-mail address removed) (Thinkit) wrote in


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.
 
T

Thomas Schodt

(e-mail address removed) (Thinkit) wrote in
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.
 
T

Thinkit

Thomas Schodt said:
(e-mail address removed) (Thinkit) wrote in


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.



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.
 
T

Thomas Schodt

(e-mail address removed) (Thinkit) wrote in
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.
 
T

Thinkit

Thomas Schodt said:
(e-mail address removed) (Thinkit) wrote in


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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top