Re: Decimal versus binary arithmetic was Re: J4 - presentation/discussion on "Future of the COBOL Standard"
- From: Robert <no@xxxxxx>
- Date: Sat, 05 Apr 2008 18:18:13 -0600
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:
inaccurate. Some refuse to
On Fri, 04 Apr 2008 00:13:23 -0600, Robert <no@xxxxxx> wrote:
You thought that because 'everyone knows' binary fractions are
point -- we could havebelieve the number is an integer, not a fraction. That was my whole
binary all along. Webeen storing currency amounts (dollars/pounds/zlotnys and cents) in
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
.
- Follow-Ups:
- References:
- Re: Decimal versus binary arithmetic was Re: J4 - presentation/discussion on "Future of the COBOL Standard"
- From: Frank Swarbrick
- Re: Decimal versus binary arithmetic was Re: J4 - presentation/discussion on "Future of the COBOL Standard"
- From: Clark F Morris
- Re: Decimal versus binary arithmetic was Re: J4 - presentation/discussion on "Future of the COBOL Standard"
- From: Frank Swarbrick
- Re: Decimal versus binary arithmetic was Re: J4 - presentation/discussion on "Future of the COBOL Standard"
- From: Robert
- Re: Decimal versus binary arithmetic was Re: J4 - presentation/discussion on "Future of the COBOL Standard"
- From: Howard Brazee
- Re: Decimal versus binary arithmetic was Re: J4 - presentation/discussion on "Future of the COBOL Standard"
- From: Robert
- Re: Decimal versus binary arithmetic was Re: J4 - presentation/discussion on "Future of the COBOL Standard"
- From: tlmfru
- Re: Decimal versus binary arithmetic was Re: J4 - presentation/discussion on "Future of the COBOL Standard"
- Prev by Date: Re: Decimal versus binary arithmetic was Re: J4 - presentation/discussion on "Future of the COBOL Standard"
- Next by Date: Re: Decimal versus binary arithmetic was Re: J4 - presentation/discussion on "Future of the COBOL Standard"
- Previous by thread: Re: Decimal versus binary arithmetic was Re: J4 - presentation/discussion on "Future of the COBOL Standard"
- Next by thread: Re: Decimal versus binary arithmetic was Re: J4 - presentation/discussion on "Future of the COBOL Standard"
- Index(es):
Relevant Pages
|