Thread View: comp.lang.modula2
4 messages
4 total messages
Started by M. Klepcyk
Mon, 26 Feb 1996 08:43
Other Modula-2 Problems
Author: M. Klepcyk
Date: Mon, 26 Feb 1996 08:43
Date: Mon, 26 Feb 1996 08:43
18 lines
1147 bytes
1147 bytes
Hi, I have some other questions also. I have to make a program that uses infinite series to approximate the value of SIN (a). The line that my teacher gave me for this is: "sin(a)=a-a3/3!+a5/5!-a7/7!+a9/9!...." What does this translate to in the way of a formula? I need to know this so I can write a procedure that will use the variable that will obviously be involved. Another problem concerns writing a procedure that will computer the binary XOR's of two decimal numbers. I know how to get the binary values for each of the decimal numbers (using MOD & DIV), but how do I compare the two binary numbers when I'm finished with this? Is there some kind of comparison command like with strings? Please advise. Thanks in advance!
Re: Other Modula-2 Problems
Author: Neil D. Bentley
Date: Tue, 27 Feb 1996 22:39
Date: Tue, 27 Feb 1996 22:39
29 lines
1795 bytes
1795 bytes
In article <313171a2.15277270@news-stand.acs.ohio-state.edu>, "M. Klepcyk" <mjk+@osu.edu> writes >Hi, > >I have some other questions also. I have to make a program that uses >infinite series to approximate the value of SIN (a). The line that my >teacher gave me for this is: "sin(a)=a-a3/3!+a5/5!-a7/7!+a9/9!...." >What does this translate to in the way of a formula? I need to know >this so I can write a procedure that will use the variable that will >obviously be involved. > >Another problem concerns writing a procedure that will computer the >binary XOR's of two decimal numbers. I know how to get the binary >values for each of the decimal numbers (using MOD & DIV), but how do I >compare the two binary numbers when I'm finished with this? Is there >some kind of comparison command like with strings? > >Please advise. > >Thanks in advance! > Do universities teach anything these days or do they just depend on Usenet to help sort out the problems? This student has asked three fairly elementary questions within twenty minutes. Can I suggest that Ohio State University recommend some basic books on programming after all it helps to be able to walk before trying to run! -- Neil D. Bentley Neil@grace35.demon.co.uk
Re: Other Modula-2 Problems
Author: Peter Moylan
Date: Tue, 27 Feb 1996 22:41
Date: Tue, 27 Feb 1996 22:41
99 lines
5460 bytes
5460 bytes
M. Klepcyk (mjk+@osu.edu) wrote:
>I have some other questions also. I have to make a program that uses
>infinite series to approximate the value of SIN (a). The line that my
>teacher gave me for this is: "sin(a)=a-a3/3!+a5/5!-a7/7!+a9/9!...."
>What does this translate to in the way of a formula? I need to know
>this so I can write a procedure that will use the variable that will
>obviously be involved.
Come on, this is too easy. You should work this one out
for yourself.
>Another problem concerns writing a procedure that will computer the
>binary XOR's of two decimal numbers. I know how to get the binary
>values for each of the decimal numbers (using MOD & DIV), but how do I
>compare the two binary numbers when I'm finished with this? Is there
>some kind of comparison command like with strings?
This, however, deserves more comment. I've noticed that
students often get confused over what is meant by "binary number"
and "decimal number" in the context of programming.
The names "binary" and "decimal" refer to the _representation_
of a number, as distinct from the underlying object which is the
number itself. You're probably aware that "101 binary" and
"5 decimal" are not two distinct numbers, but instead are two
alternative ways of writing the _same_ number. It's a bit like
saying that "pomme" and "apple" are two ways of saying the
same thing: different languages are used, but despite the
different words we're still talking about the same fruit.
When manipulating numbers in a computer program, we have to be
aware of a number of different concepts:
1. The number itself. This is an abstract object which can
be defined by, for example, a mathematician's set of axioms
for arithmetic. I can't write down an example, because as
soon as I'd written it down I would have written a
representation of the number, rather than the number itself.
2. The representation of the number inside the computer's
memory. For most present-day computers this is a binary
representation - or, more precisely, it is a collection
of electrical signals which in turn are representations of
binary digits - but it doesn't have to be. A hardware
designer could, if he wished, build a computer in which
ternary representations were used internally.
3. The representation of the number in the source code of
your computer program. This depends on the rules of the
programming language. For most programming languages a
decimal notation is used, but there are other possibilities.
(Modula-2 also has a way to use octal or hexadecimal
notation.) The important point is that the representation
doesn't have to be - and usually isn't - the same as the
representation in 2 above. The compiler takes care of
translating the notation.
4. The representation of the number in the external interface;
for example, the way the number is typed at the keyboard, or the
way it is printed on the screen. This depends on the I/O
routines you use. The I/O routines most commonly used
perform a translation between an external notation
(usually decimal) and an internal representation (usually
binary). But that's not compulsory, you could write your
own formatting procedures that used any base you liked.
This might all sound like quibbling, but it has a bearing on
your question. Let's look at the question again. You said
"compute the binary XORs of two decimal numbers". Right there,
the problem is badly posed. What it should say is something
like "compute the binary XORs of two numbers". They're
numbers, not decimal numbers, and the distinction is important.
There's no such thing as a decimal number. (Although,
informally, we often use the phrase "decimal number" as a
shorthand way of saying "decimal representation of a number"
- which in some ways is a pity, because it's this sloppy
terminology which is the root of the confusion.)
When you write a statement like "abc := 23", is abc a decimal
number? Most decidedly not! The character string "23" is the
decimal representation of a number, but that's where it ends.
The variable abc holds a number - not a decimal number - and,
depending on your computer hardware, the internal representation
is probably binary.
Now, this doesn't give an answer to your original question.
I don't want to give an answer, because I think it's
something that you have to work out for yourself. But
I'll at least give you a hint: if you're thinking of using
DIV and MOD to convert between decimal and binary, then
you're completely on the wrong track. You shouldn't have
to do any conversions.
--
Peter Moylan peter@ee.newcastle.edu.au
http://www.eng.newcastle.edu.au/ee/Moylan.html
OS/2 freeware list at
http://www.eng.newcastle.edu.au/ee/Moylan/os2/os2info.html
Re: Other Modula-2 Problems
Author: "Mark Morgan Lloyd "
Date: Mon, 04 Mar 1996 17:43
Date: Mon, 04 Mar 1996 17:43
23 lines
1428 bytes
1428 bytes
> I have some other questions also. I have to make a program that uses > infinite series to approximate the value of SIN (a). The line that my > teacher gave me for this is: "sin(a)=a-a3/3!+a5/5!-a7/7!+a9/9!...." > What does this translate to in the way of a formula? I need to know > this so I can write a procedure that will use the variable that will > obviously be involved. Sorry, this is trivial algebra and you shouldn't need to ask. > Another problem concerns writing a procedure that will computer the > binary XOR's of two decimal numbers. I know how to get the binary > values for each of the decimal numbers (using MOD & DIV), but how do I > compare the two binary numbers when I'm finished with this? Is there > some kind of comparison command like with strings? This does not make sense. Try expressing your problem a bit better and you may be able to work out what you're trying to do. Mark Morgan Lloyd mark_tbu@cix.compulink.co.uk [Opinions above are the author's, not those of his employers or colleagues]
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads