News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

add+mul

Started by imadhx30, February 01, 2014, 11:19:40 AM

Previous topic - Next topic

raymond

imadhx30

Before you ever start programming anything mathematical, you must first use your brain to determine if there is an easier way to perform the calculation. Something which may take hours to get the result on a computer may happen to take a fraction of a second when the process can be simplified.

For example, your equation can be expressed as a much more simple one which you learn in early high school algebra:
a0*bn+...........................+an*b0 is equivalent to:
(bn+1 - an+1)/(b-a)

Even with the simplification offered by qWord, you could be computing for a long time if the value of n is very high. With the simplified equation, you only need to compute two powers, two subtractions and one division.

Depending on which limits you accept for your a, b and n values (which limits you must check even before starting your computation),  you then provide code to avoid overflows either with integer instructions or floating point instructions. If the expected answer would exceed 64-bit integers with older computers (or 128 bits on modern 64-bit computers), your code would then have to rely on integer instructions using a bignum library if you need the answer exact to the least significant digit.

Have fun. Nobody here will provide you with the required code. You will now have to do your homework yourself.
Whenever you assume something, you risk being wrong half the time.
https://masm32.com/masmcode/rayfil/index.html

dedndave

thanks Ray - i knew we were doing the hard way   :biggrin:

Gunther

Dave,

Quote from: dedndave on February 02, 2014, 02:30:51 AM
i think there's a way to solve the geometric series without iteration
i just don't remember what it is   :lol:

that's not necessarily a geometric series.

Gunther
You have to know the facts before you can distort them.

imadhx30

thanks Ray (y)
:t :t :t :t :t

dedndave

if a = b
a0 bn + a1 bn-1 +....+ an b0 = (n+1) an

if a <> b
a0 bn + a1 bn-1 +....+ an b0 = (bn+1 - an+1) / (b - a)

K_F

Quote from: raymond on February 02, 2014, 12:40:51 PM
imadhx30

Before you ever start programming anything mathematical, you must first use your brain to determine if there is an easier way to perform the calculation. Something which may take hours to get the result on a computer may happen to take a fraction of a second when the process can be simplified.
Talking about this.. you might find this PDF usefull - I consult it many times - cannot remember where I found it - had it for many moons :)

https://www.dropbox.com/s/9fkq6lg5xqcce7o/ProgrammersAlgorithms.pdf
'Sire, Sire!... the peasants are Revolting !!!'
'Yes, they are.. aren't they....'

dedndave

very nice Van   :t

TWell


dedndave


Gunther

It's a crazy but hard working guy.

Gunther
You have to know the facts before you can distort them.

Gunther

I can also recommend the following book by Jörg Arndt.

Gunther
You have to know the facts before you can distort them.