# java quadratic program output error

Discussion in 'Web Design & Coding' started by mooo, Feb 27, 2004.

1. ### mooothecyberninja

Messages:
886
Location:
earth
when i input these values it gives me an output of NaN
a = 1
b = 2.1
c = 1.010025

any ideas why? i don't even have an output for NaN anywhere

forgot to post link to look at it

2. ### j79zlrGlaanies script monkeyPolitical User

Messages:
2,725
Location:
Chicago
NaN = not a number, the solution must be imaginary. is that in the form ax^2 + bx + c = 0 [shouldn't be imaginary]?

3. ### X-Istence*Political User

Messages:
6,498
Location:
USA
First off, you learn in math that the numbers CANNOT be decimal/fractions so youd need to unfractionalize em. (Dun know how)

4. ### mooothecyberninja

Messages:
886
Location:
earth
what are you talkling about numbers can not be decimal?
double and float make it so you can have decimal places not whole intergers

5. ### X-Istence*Political User

Messages:
6,498
Location:
USA
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.

6. ### j79zlrGlaanies script monkeyPolitical User

Messages:
2,725
Location:
Chicago
a, b, c do not have to be integers? [-b +/- sqrt(b^2 - 4*a*c)]/[2*a]

7. ### GeffyModeratorFolding Team

Messages:
7,805
Location:
United Kingdom
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

8. ### MdSalihThe Boss

Messages:
1,730
Location:
Birmingham, UK
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

9. ### GeffyModeratorFolding Team

Messages:
7,805
Location:
United Kingdom
thats the bit I was lookin in my maths book for
you should test the discriminate before performing the calculation to make sure that you arent going to get imaginary numbers

10. ### mooothecyberninja

Messages:
886
Location:
earth
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