Hello..

I am a newbie in assembly... so I don't know those FPU instructions and did not deal with them at all...

I need a program that solves a quadratic equation using the discriminant.

that is x=(-b+-sqrt(4ac))/(2a)

input: a,b,c

output: x1, x2

ignoring imaginary numbers.. as simple as that.

Can u help me out?

I am a newbie in assembly... so I don't know those FPU instructions and did not deal with them at all...

I need a program that solves a quadratic equation using the discriminant.

that is x=(-b+-sqrt(4ac))/(2a)

input: a,b,c

output: x1, x2

ignoring imaginary numbers.. as simple as that.

Can u help me out?

Hey.. I forgot to tell u :)...

I have MASM611 and don't deal with Win32asm.

DOS environment only..

I have MASM611 and don't deal with Win32asm.

DOS environment only..

Well get started... :)

And when you find you got a prob, ask us... But we wont do your homework for you :) (Im assuming this from the fact you want a "schoolish type equation" to be done on a 16 bit compiler (something else that schools typically favor). Oh ya, and your quadratic formula is wrong, :) ... the root is wrong.. should be sqrt( B^2 - 4(A)(C) )... )

As a hint to get you going in the right direction, get Zakiel's floating point tutorials... (He also goes by Eoin).. you can find them by searchin the board with the search button (top right, off screen). Look for "floating Point" and see what it drags up. :)

If not, search the web for the Art of Assembly online pdf. AoA for short. There is an entire chapter on floating point.

Good luck..

NaN

And when you find you got a prob, ask us... But we wont do your homework for you :) (Im assuming this from the fact you want a "schoolish type equation" to be done on a 16 bit compiler (something else that schools typically favor). Oh ya, and your quadratic formula is wrong, :) ... the root is wrong.. should be sqrt( B^2 - 4(A)(C) )... )

As a hint to get you going in the right direction, get Zakiel's floating point tutorials... (He also goes by Eoin).. you can find them by searchin the board with the search button (top right, off screen). Look for "floating Point" and see what it drags up. :)

If not, search the web for the Art of Assembly online pdf. AoA for short. There is an entire chapter on floating point.

Good luck..

NaN

Oh no... i did the same mistake again... yeah... thanks for the correction...

Anyways, i will try to make use of those tuturials and the AOA, but of course any help would be greatly appreciated.

Thanks again and iam waiting for any help, at least for the square root prob.

thanks

Anyways, i will try to make use of those tuturials and the AOA, but of course any help would be greatly appreciated.

Thanks again and iam waiting for any help, at least for the square root prob.

thanks

This is no real need for more help in this area, look at Zakiel's first tut. It has every operation you need in it...

Well almost, since you are doing a quadratic, you need to do a comparison to determin if the ROOTS are REAL or IMAGINARY.

After all, you cant sqrt a negative number on a computer. But you can multiply it by -1, squar root it, and assume that term as imaginary.

More little tid bits to think about.

(Below is Zakiel's first tut ~ I couldnt find them on here.. must have been on the old board..)

Well almost, since you are doing a quadratic, you need to do a comparison to determin if the ROOTS are REAL or IMAGINARY.

After all, you cant sqrt a negative number on a computer. But you can multiply it by -1, squar root it, and assume that term as imaginary.

More little tid bits to think about.

(Below is Zakiel's first tut ~ I couldnt find them on here.. must have been on the old board..)

Thanks again for the help...

the problem is that i am not familiar with win32asm...

and believe it or not, i don't know what exactly the difference b/ this and my old asm!

hmmm... i need to put my newer question in a seperate thread..

thanks.... and maybe to come back again :)

the problem is that i am not familiar with win32asm...

and believe it or not, i don't know what exactly the difference b/ this and my old asm!

hmmm... i need to put my newer question in a seperate thread..

thanks.... and maybe to come back again :)

psssst, you guys know that using the gradeschool algos isn't recommended? I'm stating the obvious in that they are good for paper & pen but bad for computers? Using

x= [-b (+-) sqrt( b^2 -4ac)]/2a

=2c/[[-b (+-) sqrt(b^2 - 4ac)]

when either a or c are near zero will cause one of the roots to be be horribly inacurate. Instead use

q = -

x= [-b (+-) sqrt( b^2 -4ac)]/2a

=2c/[[-b (+-) sqrt(b^2 - 4ac)]

when either a or c are near zero will cause one of the roots to be be horribly inacurate. Instead use

q = -

**/2**

x1 = q/a & x2 = c/q

for complex numbers see the full explanation at http://lib-www.lanl.gov/numerical/bookcpdf.html

Other books have a more complete explanation (very breifly covered in this book... i don't really like it too much) but I'm away from my library right now... & this is the only link i could google up on the topic. These revised algos are so old I couldn't even get close to finding the primary documentation on the web.x1 = q/a & x2 = c/q

for complex numbers see the full explanation at http://lib-www.lanl.gov/numerical/bookcpdf.html

Other books have a more complete explanation (very breifly covered in this book... i don't really like it too much) but I'm away from my library right now... & this is the only link i could google up on the topic. These revised algos are so old I couldn't even get close to finding the primary documentation on the web.

**
**

Thanx for the tip, i presently use DAP, and it assures me i have the lastest version. But after your post i looked up the web page and realize there is now a v.5 (?) So i think my DAP is a little confused :) . I will have to look into it.. not too keen on extra wing-dings on my IE explorer tho, there is enough crap up there to begin with :)

Thanx, its nice to be appreciated.

Thanx for the sugestions. I personally didnt like GetRight when i tried it a few years ago. But perhaps its worth lookin into again. I also "tried" to d/l the WebZip, but the server was tooo slow for my patience :)

Since you gave teleport pro such high regard i thought i would check it out, but the link is dead. Do you know of any mirror sites etc??

Anywho, the reason im reluctant to get GetRight or WebZip is because they are all installed GUI programs. I grew up with DOS and the DOS tool. And im stuck in this mental rutt. I dont believe a tool should be a full fledge, must re-start your computer after installed program. A tool should be turned on, used, and turned off. The end. (And hopefully under 1 MB) However, after hunting on Download.com i dont think i will find what i hope for without making it myself.

NaN

rafe,

This is a truely awesome reference page! Thanx alot!.

This is why i love this board. All my friends think ASM is a narrow and dead end area to be wasting my time, but its getting treasures like this page that makes it more than just programming. :) Seems over the last year, I have found info on every area of "technical" interest i have, other than ASM itself (Mainly thru free and random replies such as your own).

MASM32 is mearly the stepping stone...

Thanx again!

PS: Anyone know of a good ripping tool to download all the PDF's and the web page to a dir? (I usually do i manually, but this looks like a big job :) )

NaN

This is a truely awesome reference page! Thanx alot!.

This is why i love this board. All my friends think ASM is a narrow and dead end area to be wasting my time, but its getting treasures like this page that makes it more than just programming. :) Seems over the last year, I have found info on every area of "technical" interest i have, other than ASM itself (Mainly thru free and random replies such as your own).

MASM32 is mearly the stepping stone...

Thanx again!

PS: Anyone know of a good ripping tool to download all the PDF's and the web page to a dir? (I usually do i manually, but this looks like a big job :) )

NaN

Hi NaN!

Get download accelerator plus. In the newest version, there is a "DAP Bar" that is situated in the toolbar in Internet Explorer. It has a leech function that can download everything on a page.

/Delight

Get download accelerator plus. In the newest version, there is a "DAP Bar" that is situated in the toolbar in Internet Explorer. It has a leech function that can download everything on a page.

/Delight

Rafe, whats the difference between those two equations. I was always intrested in the speed of calculations rather than accuracy so I never studied the potential problems.

However from looking at the two equation it seems to me that they would both be coded in a similar fashion.

I'm sure I'm wrong here as I have little experience of this aspects of maths on computers, maybe somone could enlighten me. :)

Also does anyone know of the best way the code the sgn function in assembly. According to my vb help it works as follows:

This could be annoyingly slow if it had to be coded with conditional jumping. Perhaps theres a neat asm trick out there to do this efficiently.

:stupid:

However from looking at the two equation it seems to me that they would both be coded in a similar fashion.

I'm sure I'm wrong here as I have little experience of this aspects of maths on computers, maybe somone could enlighten me. :)

Also does anyone know of the best way the code the sgn function in assembly. According to my vb help it works as follows:

```
If number is Sgn returns
```

Greater than zero 1

Equal to zero 0

Less than zero -1

This could be annoyingly slow if it had to be coded with conditional jumping. Perhaps theres a neat asm trick out there to do this efficiently.

:stupid:

NaN,

You're welcome but your own contributions are really appreciated by me & many others. You are a one, of many, of folks here who know their shit & are very generous with their time. I'm hoping to move out of leech-mode myself soon. I LOVE THIS BOARD!

E?in ne Zadkiel,

I had the same problem as I looked at my own post later in the day. OK, Back home today & altho the link is a snail's 30K I have my blessed library. Fair warning this is "book learning" & i haven't tried to implement these in ... well aside from vb once... never & never really tested the concepts myself (danger Will Robinson).

Hamming's book, which I prefer due to less hand waving & clear explainations of basic concepts, "Numerical Methods for Scientists & Engineers" Dover Press 1986 reprint from 1961 (~US$17) covers this stuff ad nauseum. The field has marched on since 1961 but the basics are still valid & that's what he covers.

According to him the trick here is to use the standard equation for one root, x1.

x1 = [-b (opposite sign of b) sqrt(b^2 - 4ac)]/2a

& then use...

x2 = c/(a * x1)

He goes thru the process of rebuilding the the original quadratic equations both ways from the derived roots of x^2 + 80x + 1 = 0

Using the limited precision of 3 decimal digits throughout all calculations. In realistic modern examples you'll have to take it out farther to get a difference & i am probobly undercutting my own case for relevance here

original method yields with 3-digit precision throughout you'll get

x1 = 80 & x2 =0

but using the cancellation method you get roots with same precision throughout: x1=80 & x2=.0125.

Now the roundtrip rebuild of the quadratic from the calculated roots will obviously be better on the second one with this, contrived to make the point, example.

PS: I've seen your posts & tutes you don't fool me :D Where I have a few books & no real experince, you've got plenty of practical experience on FPU algos & can easily get the book. I'd rather be in your shoes :)

You're welcome but your own contributions are really appreciated by me & many others. You are a one, of many, of folks here who know their shit & are very generous with their time. I'm hoping to move out of leech-mode myself soon. I LOVE THIS BOARD!

E?in ne Zadkiel,

I had the same problem as I looked at my own post later in the day. OK, Back home today & altho the link is a snail's 30K I have my blessed library. Fair warning this is "book learning" & i haven't tried to implement these in ... well aside from vb once... never & never really tested the concepts myself (danger Will Robinson).

Hamming's book, which I prefer due to less hand waving & clear explainations of basic concepts, "Numerical Methods for Scientists & Engineers" Dover Press 1986 reprint from 1961 (~US$17) covers this stuff ad nauseum. The field has marched on since 1961 but the basics are still valid & that's what he covers.

According to him the trick here is to use the standard equation for one root, x1.

x1 = [-b (opposite sign of b) sqrt(b^2 - 4ac)]/2a

& then use...

x2 = c/(a * x1)

He goes thru the process of rebuilding the the original quadratic equations both ways from the derived roots of x^2 + 80x + 1 = 0

Using the limited precision of 3 decimal digits throughout all calculations. In realistic modern examples you'll have to take it out farther to get a difference & i am probobly undercutting my own case for relevance here

**BUT modern FPUs are still limited precision instuments so the basic concepts should still apply... just farther out!**original method yields with 3-digit precision throughout you'll get

x1 = 80 & x2 =0

but using the cancellation method you get roots with same precision throughout: x1=80 & x2=.0125.

Now the roundtrip rebuild of the quadratic from the calculated roots will obviously be better on the second one with this, contrived to make the point, example.

PS: I've seen your posts & tutes you don't fool me :D Where I have a few books & no real experince, you've got plenty of practical experience on FPU algos & can easily get the book. I'd rather be in your shoes :)

hi

rafe

:

i was wondering how did you get

x= [-b (+-) sqrt( b^2 -4ac)]/2a =2c/[[-b (+-) sqrt(b^2 - 4ac)]

'[-b (+-) sqrt( b^2 -4ac)]/2a =2c/[[-b (+-) sqrt(b^2 - 4ac)]'

fix me if i wrong buy this will be true only when delta = 0.

bye

eko

rafe

:

i was wondering how did you get

x= [-b (+-) sqrt( b^2 -4ac)]/2a =2c/[[-b (+-) sqrt(b^2 - 4ac)]

'[-b (+-) sqrt( b^2 -4ac)]/2a =2c/[[-b (+-) sqrt(b^2 - 4ac)]'

fix me if i wrong buy this will be true only when delta = 0.

bye

eko

for complete website grabbing, I swear to teleport pro (www.tenmax.com).

It works and is automated.

It works and is automated.

eko, I'm not certian that this will help but...

First given that the standard form of the quadratic equation is:

ax^2 + bx + c = 0 (0 aka delta here), delta is zero by definition.

I had to practice my rusty algebra to get this much for you. For a brief glossing over of how one gets the 2nd equation & therefore the "improved" algo...

given that a(x-x1)(x-x2)=ax^2 - a(x1+x2)x + a*x1*x2

it should be apparent by inspection that x1 * x2 = c/a so...

x2 = c/(a*x1) &

2c/[-b (+-) sqrt(b^2 - 4ac)] will follow from a direct substition into c/(a*x) with the [-b (+-) sqrt( b^2 -4ac)]/2a form most are familiar with.

All the "improved" algo does is to use this x2 = c/(a*x1) to order math ops to limit inopportune cancellations which will then cause inaccuracies

Hope this helps

Edit to correct typo in equations

First given that the standard form of the quadratic equation is:

ax^2 + bx + c = 0 (0 aka delta here), delta is zero by definition.

I had to practice my rusty algebra to get this much for you. For a brief glossing over of how one gets the 2nd equation & therefore the "improved" algo...

given that a(x-x1)(x-x2)=ax^2 - a(x1+x2)x + a*x1*x2

it should be apparent by inspection that x1 * x2 = c/a so...

x2 = c/(a*x1) &

2c/[-b (+-) sqrt(b^2 - 4ac)] will follow from a direct substition into c/(a*x) with the [-b (+-) sqrt( b^2 -4ac)]/2a form most are familiar with.

All the "improved" algo does is to use this x2 = c/(a*x1) to order math ops to limit inopportune cancellations which will then cause inaccuracies

Hope this helps

Edit to correct typo in equations

hiii

i'm not sure if we understand each other .

i learned . delta is (b^2-4ac )..

any way .

i'm understand you

2c/[-b (sign ) sqrt(b^2 - 4ac)] = [-b (oposite sign ) sqrt(b^2 - 4ac)] /2a

i never thought about like this .. nice .

bye

eko

ax^2 + bx + c = 0 (0 aka delta here),

i'm not sure if we understand each other .

i learned . delta is (b^2-4ac )..

any way .

i'm understand you

2c/[-b (sign ) sqrt(b^2 - 4ac)] = [-b (oposite sign ) sqrt(b^2 - 4ac)] /2a

i never thought about like this .. nice .

bye

eko

**Delight**,

Thanx for the tip, i presently use DAP, and it assures me i have the lastest version. But after your post i looked up the web page and realize there is now a v.5 (?) So i think my DAP is a little confused :) . I will have to look into it.. not too keen on extra wing-dings on my IE explorer tho, there is enough crap up there to begin with :)

**rafe**,

Thanx, its nice to be appreciated.

**bitRAKE**,

Thanx for the sugestions. I personally didnt like GetRight when i tried it a few years ago. But perhaps its worth lookin into again. I also "tried" to d/l the WebZip, but the server was tooo slow for my patience :)

**f0dder**,

Since you gave teleport pro such high regard i thought i would check it out, but the link is dead. Do you know of any mirror sites etc??

Anywho, the reason im reluctant to get GetRight or WebZip is because they are all installed GUI programs. I grew up with DOS and the DOS tool. And im stuck in this mental rutt. I dont believe a tool should be a full fledge, must re-start your computer after installed program. A tool should be turned on, used, and turned off. The end. (And hopefully under 1 MB) However, after hunting on Download.com i dont think i will find what i hope for without making it myself.

NaN

NaN, give a look at wget (http://www.gnu.org/software/wget/wget.html). It is a GNU open source download manager born under *nix, but available also precompiled for win32, of course it isn't a GUI tool :).

for web ripping i use httrack (www.httrack.com), it's very good and free.

sgn( x ) = x / abs( x )

How can one implement this in asm w/o FPU

I use FPU but i wondered.

How can one implement this in asm w/o FPU

I use FPU but i wondered.