Division with a Stamp
Newzed
Posts: 2,503
Post deleted until I can fix the error Tracy found.
Sid
Post Edited (Newzed) : 11/30/2005 9:24:00 PM GMT
Sid
Post Edited (Newzed) : 11/30/2005 9:24:00 PM GMT
Comments
I'm here to to nit pick a bit! I think the last line in your program has to be refined. It can't be just,
DEBUG "Quotient is ", DEC q, ".", DEC y, cr, cr
Depending on the number of decimal places, (your variable z), it has to select one of these:
DEBUG "Quotient is ", DEC q, ".", DEC3 y, cr, cr
or
DEBUG "Quotient is ", DEC q, ".", DEC2 y, cr, cr
or
DEBUG "Quotient is ", DEC q, ".", DEC1 y, cr, cr
Otherwise you end up with something that should be, e.g., 5.001, being displayed as 5.1.
It is possible to extend the result to more decimal places (an arbitrary number of decimal places in fact, for display purposes), by repeatedly taking both a quotient and a remainder, and at each step, the remainder is multiplied by the factor (1000,100, 10) and that then makes a new quotient and remainder.
A note on terminology: What your are calling the "modulus" is usually called the "remainder". The notion of modulus is more synonymous with "divisor".
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Oh, the agony of it all........................
Sid
After studying about it for a bit, I agree that the use of the word "modulus" in inappropriate.
I have substituted the word "remainder" for the word "modulus" where ever it appears.
The superfluous "y = x*z/d" after the IF statements has been deleted.
I modified the IF statements to use ELSEIF wherever appropriate.
For easy reference, I have placed the computational routines under the label "calc".
calc:
IF x<=655 THEN
z = 100
y = x*z/d 'decimal part = remainder times multiplier divided by
·················· divisor
ELSEIF x<=6553 THEN
z = 10
d = d/10
y = x*z/d 'decimal part =remainder times multiplier divided by
··················· divisor
ELSEIF x>6553 THEN
z = 1
d = d/100
y = x*z/d 'decimal part = remainder times· multiplier·divided
··················· by divisor···
ENDIF
DEBUG "Quotient is ", DEC q, ".", DEC2 y, cr, cr
DEBUG "Press any key to continue", cr
DEBUGIN com
GOTO main
The statement IF x<=65 has been deleted since it is computationally identical to the IF x<=655 statement.
I had to retain the IF statment "IF x>6355" statement because
this statement allows me to change the values of z and d.
The values of·z and d have been adjusted in each IF statement so that the ratio of x*z to d is always 100:1. This allows the use of two decimals places in the DEBUG Quotient statements. It also allows deletion of the three conditional DEBUG Quotient statements, which really cleans up the program.
I believe this corrects all the deficiencies you noted. I will wait for·your comment before I post Rev A.
Sid
This program is designed primarily for new Stampers, showing how you can derive decimals with a Stamp.
It is written for a BS2 but will work with any Stamp from a BS2 on up.
Sid
Post edited by Newzed
Post Edited (Newzed) : 12/5/2005 6:29:28 PM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Post Edited (Tracy Allen) : 12/6/2005 4:16:48 PM GMT
Incidentally, according to my calculator 355/115 = 3.0869565217, not 3.1415929203,
when 10 digits are specified.
Guess I'm a nit-picker, too
Sid
P.S. The sequence of best rational approximations to pi is,
3, 22/7, 333/106, 355/113, 103993/33102, 104348/33215, ...
That is, 355/113 is a good approximation, as it has to jump all the way up to a denominator of 33102 to get to a closer approximation. These are "convergents" of the continued fraction expansion of pi.
Numbers like 1/7, 2/7, 3/7 etc. are interesting because the decimal expansion is a short repeating sequence. Looking at the expansions could be a good "stamps in math class" exercise.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Post Edited (Tracy Allen) : 12/6/2005 6:09:48 PM GMT