java quadratic program output error

j79zlr

Glaanies script monkey
Political User
Joined
Feb 16, 2003
Messages
2,725
#2
NaN = not a number, the solution must be imaginary. is that in the form ax^2 + bx + c = 0 [shouldn't be imaginary]?
 

X-Istence

*
Political User
Joined
Dec 5, 2001
Messages
6,498
#3
First off, you learn in math that the numbers CANNOT be decimal/fractions so youd need to unfractionalize em. (Dun know how)
 

mooo

thecyberninja
Joined
Jan 6, 2004
Messages
886
#4
what are you talkling about numbers can not be decimal?
double and float make it so you can have decimal places not whole intergers
 

X-Istence

*
Political User
Joined
Dec 5, 2001
Messages
6,498
#5
The first thing you are taught about ax^2 + bx + c = 0 is that A, B, and C have to be integers and no decimal, or fractions.

Dont believe me if you wish to do so, but that could be the reason it is coming up with that answer.
 

j79zlr

Glaanies script monkey
Political User
Joined
Feb 16, 2003
Messages
2,725
#6
a, b, c do not have to be integers? [-b +/- sqrt(b^2 - 4*a*c)]/[2*a]
 

Geffy

OSNN Veteran Addict
Joined
Mar 18, 2002
Messages
7,805
#7
they dont have to be ints but can you tell us what happens if you only use ints, well I mean like the types are double or float but your input is whole numbers
 
Joined
Dec 2, 2001
Messages
1,730
#8
a,b,c can be anything you like... but for ease of human calculations it's better to have them as real integers (to get rid of fractions/decimals multiply through by a common denominator/factor)

It's just that the discriminate (b^2-4ac) must be >= 0 for it to give a real answer. Else you'll go into imaginary numbers.

MdSalih
 

Geffy

OSNN Veteran Addict
Joined
Mar 18, 2002
Messages
7,805
#9
thats the bit I was lookin in my maths book for :p
you should test the discriminate before performing the calculation to make sure that you arent going to get imaginary numbers
 

mooo

thecyberninja
Joined
Jan 6, 2004
Messages
886
#10
i figured out some of my output problems :)
forgot a ( )to enclude the -b,, it was dividing over just the sqrt then adding or sub the -b :) gotta work on my float epsilon point now i guess
 

Members online

No members online now.

Latest posts

Latest profile posts

Perris Calderon wrote on Electronic Punk's profile.
Hey ep!

All good with me, applying for microsoft mvp right now, should have done this a while ago.

Notifications don't work, I only found your response by comming back to hunt up some threads, if you want, give me your email address so we can keep in touch easier, mine is perriscalderon at gmail
Perris Calderon wrote on Electronic Punk's profile.
Ep, glad to see you come back and tidy up...did want to ask a one day favor, I want to enhance my resume , was hoping you could make me administrator for a day, if so, take me right off since I won't be here to do anything, and don't know the slightest about the board, but it would be nice putting "served administrator osnn", if can do, THANKS

Been running around Quora lately, luv it there https://tinyurl.com/ycpxl
Electronic Punk wrote on Perris Calderon's profile.
All good still mate?
Hello, is there anybody in there? Just nod if you can hear me ...

Forum statistics

Threads
62,028
Messages
673,529
Members
89,038
Latest member
Samhicks