Re: low level- logs/sqrts?


[Prev][Next][Index][Thread]

Re: low level- logs/sqrts?



Dylan R Wade writes:

>         I was thinking of converting some of my basic calc-programs to
> asm, one major roadblock that bugs
> me is that I don't know how to find logs and sqrts without a calculator
> or a table?  I can't find it in any basic math books, usu. you just use
> the calculator, but in low level programming there is no SQR or LOG
> opcode (at least i dont think so).  Anyway that's something i have not
> really knew how to do either.  Given that there are lots of math majors'
> and pHd's here could someone help me out?  How do you find any sqrt
> and/or log by hand??
>

The theory on this is studied in calculus and other courses at that level.
The topic is really numerical methods, which is often taught as part of
a computer science program, sometimes by faculty in the math department
and sometimes not.

But you are likely to be more interested in the _practice_, unless you want to
get very, very serious about efficiency of your code, etc. Again the topic
is numerical methods.  Check out books on this topic in a public library.
One good series is the Numerical Recipes books, available in several different
language "flavors".

However, you can probably write your own square root extraction routine from
scratch. The standard algorithm (and a very effective one) is "divide and
average", which takes an initial guess (it's always safe to start with 1) and
improves it at each step until you reach a satisfactory result.  The
improvement is performed by dividing your target (the number you are finding
the square root of) by your guess, and then just averaging the guess and the
result of the division to arrive at a new guess.  This assumes, of course,
that you have access to a division routine in your language environment (I
think you can get by without any multiplies). If not, you will have to set this
up too.

Logarithms are best calculated by using series (see a discussion of this in a
message on an unrelated topic that I am just about to post).  The logs of
numbers near 1 are easy to calculate, the others are best arrived at using
various slick tricks. All this would not be too easy to develop from scratch in
assembly. Depending on what you want the logs for you might be best off just
storing a small lookup table in your code.

RWW Taylor
National Technical Institute for the Deaf
Rochester Institute of Technology
Rochester NY 14623

>>>> The plural of mongoose begins with p. <<<<