Arbitrary precision binary float class

Discussion in 'Java' started by Thinkit, Dec 19, 2003.

  1. Thinkit

    Thinkit Guest

    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?
    Thinkit, Dec 19, 2003
    #1
    1. Advertising

  2. Thinkit

    Thinkit Guest

    (Thinkit) wrote in message news:<>...
    > 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.
    Thinkit, Dec 20, 2003
    #2
    1. Advertising

  3. Thinkit wrote:
    >
    > (Thinkit) wrote in message news:<>...
    > > 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)
    Lee Fesperman, Dec 21, 2003
    #3
  4. (Thinkit) wrote in
    news::

    > (Thinkit) wrote in message
    > news:<>...
    >> 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).
    Thomas Schodt, Dec 21, 2003
    #4
  5. Thinkit

    Thinkit Guest

    Thomas Schodt <news0310@xenoc.$DEMON.co.uk> wrote in message news:<Xns945898E9B5916xenoc@158.152.254.254>...
    > (Thinkit) wrote in
    > news::
    >
    > > (Thinkit) wrote in message
    > > news:<>...
    > >> 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.
    Thinkit, Dec 22, 2003
    #5
  6. (Thinkit) wrote in
    news::

    > 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.
    Thomas Schodt, Dec 22, 2003
    #6
  7. Thinkit

    Thinkit Guest

    Thomas Schodt <news0310@xenoc.$DEMON.co.uk> wrote in message news:<Xns94596C1F4B416xenoc@158.152.254.254>...
    > (Thinkit) wrote in
    > news::


    > > 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.
    Thinkit, Dec 22, 2003
    #7
  8. (Thinkit) wrote in
    news::

    > 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.
    Thomas Schodt, Dec 22, 2003
    #8
  9. Thinkit

    Thinkit Guest

    Thomas Schodt <news0310@xenoc.$DEMON.co.uk> wrote in message news:<Xns945898E9B5916xenoc@158.152.254.254>...
    > (Thinkit) wrote in
    > news::
    >
    > > (Thinkit) wrote in message
    > > news:<>...
    > >> 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?
    Thinkit, Dec 24, 2003
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Thinkit
    Replies:
    2
    Views:
    298
    Thinkit
    Nov 28, 2003
  2. bd
    Replies:
    0
    Views:
    615
  3. Martin the Third
    Replies:
    8
    Views:
    374
    Kai-Uwe Bux
    Jun 13, 2008
  4. Carsten Fuchs
    Replies:
    45
    Views:
    1,526
    James Kanze
    Oct 8, 2009
  5. Anton81

    Float precision and float equality

    Anton81, Dec 5, 2009, in forum: Python
    Replies:
    26
    Views:
    1,133
Loading...

Share This Page