Re: Decimal versus binary arithmetic was Re: J4 - presentation/discussion on "Future of the COBOL Standard"



On Sat, 5 Apr 2008 10:54:00 -0600, "tlmfru" <lacey@xxxxxxx> wrote:


Robert <no@xxxxxx> wrote in message
news:c2ldv3dtaij23o1d7h2377975e2053k57d@xxxxxxxxxx
On Fri, 04 Apr 2008 07:50:39 -0600, Howard Brazee <howard@xxxxxxxxxx>
wrote:

On Fri, 04 Apr 2008 00:13:23 -0600, Robert <no@xxxxxx> wrote:

You thought that because 'everyone knows' binary fractions are
inaccurate. Some refuse to
believe the number is an integer, not a fraction. That was my whole
point -- we could have
been storing currency amounts (dollars/pounds/zlotnys and cents) in
binary all along. We
never needed packed decimal. It was an IBM sales gimmick, and it worked.



Tip o'the (Hatlo) hat to whoever pointed this out originally -

One very good reason that pure binary representation was not used is that
decimal fractions cannot (generally) be expressed except as a repeating
number in binary. Examples: 0.2 (decimal) = .00110011 ... (binary). .12
(decimal) = .000111 etc. (binary).

To pay for something costing .50, you don't tear a dollar bill in half (a fraction), you
tender 50 pennies (an integer).

To make correct arithmetic using only binary possible, it seems to me that
ALL numbers must be implicitly scaled to remove the decimal point. If that
is your meaning, Robert, then you haven't made it clear. Binary fractions
cannot be represented accurately - period.

I did make it clear. Here's the thread:

On Mon, 31 Mar 2008 21:55:10 -0300, Clark F Morris
<cfmpublic@xxxxxxxxxxxxxxx> wrote:

Try doing a simple divide like calculate the value of 1 / 5 in binary.

OK.

01 numerator value 1 binary pic 9(9).
01 denominator value 5 binary pic 9(9).
01 quotient binary pic 9(9)v9(4).

compute quotient = numerator / denominator
display quotient

0000000002000

You get a never ending fraction.

Looks pretty diadic to me.

That's because you did not do it in binary, you did it in decimal.
One-fifth is rational in decimal, but irrational in binary.

Nope, all three numbers are binary INTEGERS. The fallacy is in thinking of quotient as a fraction. It is not a fraction, it is an integer.
The compiler SCALED two integers by multiplying by powers of 10, then divided two binary integers to get a quotient with no fraction.
Binary 10 divided by binary 5 gives binary 2.

101111101011110000100000000 / 1100001101010000 = 11111010000

Incidentally - everybody knows about the simple algoritm to convert base 10
numbers to base 2 - i.e. repeated division by 2 -
I had some fun working out the mirror algorithm to convert decimal FRACTIONS
to binary fractions. (Very easy, actually). (Both algorithms work for any
base). But what puzzles me is I've never seen this written up anywhere.
I'm certain that the early developers of computers (or perhaps IBM research
fellows) must have discovered the algorithm. Has anyone seen it written up?

There aren't any fractions in fixed-point number representations; the numbers are all
integers. If you look in memory at the variable with 'pic 99v99 value .2', you will see
'0020', which is not a fraction.

Fractions appear only in floating point systems.

Who says the number system base must be a real positive integer? In the negadecimal
system, which has -10 as its base, 8163 decimal becomes 12243 negadecimal as 10000 +
(-2000) + 200 + (-40) + 3. The advantage of negative base systems is they don't require a
sign. An imaginary base system such as the one proposed by Donald Knuth represents numbers
without an 'i' nor a sign.

The ideal numeration base is an irrational called phi or golden ratio, which is 1.61803...
The only digits are 0 and 1, which makes it ideal for computers. One would expect 'our'
integers to produce infinately repeating fractions while irrational numbers produce
terminated fractions. Not so. In phinary, EVERY number can be represented exactly in a
finite string of 0s and 1s, including e, pi and square root of 2. That's a very valuable
attribute. For more on this, see:

http://www.mcs.surrey.ac.uk/Personal/R.Knott/Fibonacci/phigits.html
http://en.wikipedia.org/wiki/Phinary

.



Relevant Pages

  • Re: Type Question
    ... this is true of all programming languages that use floating point ... Common Lisp comes pretty close to providing that as ... Change the floating point representation. ... computationally efficient binary representation, the fractions should be ...
    (comp.lang.lisp)
  • Re: Mapping rationals to binary strings while preserving order
    ... the mapped representation as a bitstream. ... may signify the two fractions 01;011 or the only fraction 01011 or even ... Is the max. denominator 9 as per your example? ...
    (comp.theory)
  • Re: need just 6 digits
    ... It is true for division of integers by powers of two in ... 1/3 does have an exact one digit representation ... NaNs and infinities, are binary fractions, each double ... digits in the fractional part from all the decimal fractions ...
    (comp.lang.java.help)
  • Re: Mapping rationals to binary strings while preserving order
    ... the mapped representation as a bitstream. ... may signify the two fractions 01;011 or the only fraction 01011 or even ... same length, the numbers are not ambigeous anymore, but then there is no ...
    (comp.theory)
  • Re: Ancient Remainder Arithmetic
    ... Ahmes always wrote out his vulgar ... fractions as a quotient and a remainder. ...
    (sci.math)