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?
Posted on 2001-10-01 17:27:43 by Spirit
Hey.. I forgot to tell u :)...

I have MASM611 and don't deal with Win32asm.

DOS environment only..
Posted on 2001-10-01 17:30:44 by Spirit
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
Posted on 2001-10-01 18:37:53 by 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
Posted on 2001-10-01 18:55:24 by Spirit
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..)
Posted on 2001-10-01 22:35:29 by NaN
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 :)
Posted on 2001-10-11 21:22:01 by Spirit
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 = -/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.
Posted on 2001-10-12 10:39:50 by rafe
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
Posted on 2001-10-13 00:05:22 by 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
Posted on 2001-10-13 01:42:00 by 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:

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:
Posted on 2001-10-13 06:45:44 by Eóin
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 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 :)
Posted on 2001-10-13 13:42:33 by rafe
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
Posted on 2001-10-13 13:54:30 by eko
NaN, GetRight allows you to browse the links on a page and selective download - it's the best I've seen. You get an easy to use tree of links and list of files on each page. Give it a try. Another program is WebZip, but it's not the best solution for this kind of thing, IMHO.
Posted on 2001-10-13 13:58:13 by bitRAKE
for complete website grabbing, I swear to teleport pro (www.tenmax.com).
It works and is automated.
Posted on 2001-10-13 14:27:42 by f0dder
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
Posted on 2001-10-13 15:40:07 by rafe
hiii


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
Posted on 2001-10-13 17:53:32 by 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
Posted on 2001-10-14 02:44:22 by 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 :).
Posted on 2001-10-14 04:42:48 by LuHa
for web ripping i use httrack (www.httrack.com), it's very good and free.
Posted on 2001-10-14 06:13:13 by doby
sgn( x ) = x / abs( x )
How can one implement this in asm w/o FPU
I use FPU but i wondered.
Posted on 2003-07-10 10:25:06 by inFinie