What Is My IP Address? - IP Address Lookup, Bandwidth Speed Test, IP Info, plus more

Go Back   What Is My IP Forum > Welcome to the WIMI Forum > Off Topic Discussions

Notices

Off Topic Discussions Anything that's not category related can go here.

Closed Thread
 
Thread Tools Display Modes
Old 12-28-2009, 05:14 PM   #1
TheOne
Member
 
Join Date: Apr 2009
Posts: 8
TheOne is on a distinguished road
Default I'm back "discriminant" Help!

Hello great folks of this great site,

As some of you know, I've been very busy studying networking and java. I have a serious question in java that's been bugging me all month:

What is the discriminant?

Can any one gives me a clear, down to earth definition of what this type is and how/when would I use it in a program?

the example code I have is below:

Code:
double b = Double.parseDouble(args[0]);
double c = Double.parseDouble(args[1]);
double discriminant = b*b - 4.0*c;
double d = Math.sqrt(discriminant);
I understand what the program is doing as far as printing the roots of the polynomials x^2 + bx + c
However, why couldn't they just use another double type variable at line 3 instead of discriminant?

wouldn't any other variable do the same operations of (b*b - 4.0*c)?

Thanks in advanced and happy new year to all

Last edited by wimiadmin; 12-28-2009 at 07:12 PM.
TheOne is offline  
Old 12-29-2009, 04:27 AM   #2
clanmills
Super Moderator
 
clanmills's Avatar
 
Join Date: Jul 2008
Location: San Jose, CA
Posts: 216
clanmills has a spectacular aura aboutclanmills has a spectacular aura aboutclanmills has a spectacular aura about
Send a message via MSN to clanmills Send a message via Skype™ to clanmills
Default

Here's an explanation of the term "discriminant" which I obtained from a google search of "discriminant quadratic". (I haven't read this - however it looks OK).

http://www.mathwords.com/d/discriminant_quadratic.htm

The java code:
Code:
double discriminant = b*b - 4.0*c;
double d = Math.sqrt(discriminant);
could be written as:
Code:
double cheeseburgerwithfriesandashake = b*b - 4.0*c;
double d = Math.sqrt(cheeseburgerwithfriesandashake);
It would mean the same. The variable name chosen by the programmer is intended to help a (human) reader to understand the code and doesn't change the execution of the code.

I assume that you inherited this code from a programmer who (rightly) believes that the variable name "discriminant" is more meaningful than "cheeseburgerwithfriesandashake".

Of course it could be written as:
Code:
double d = Math.sqrt(b*b - 4.0*c);
This would totally short cut the need for a variable name. However the java function Math.sqrt requires a non negative number. I suspect when it 'bombs' with a negative number, it'll produce a message such as 'b*b -4.0c' cannot be negative. The programmer preferred the message 'discriminant' cannot be negative.

Of course you can modify the java 'bomb' experience with try ... catch ... however that's another matter about which you'll have to learn.

Happy New Year to you. Best Wishes for 2010.

Robin

Last edited by clanmills; 12-29-2009 at 04:46 AM.
clanmills is offline  
Closed Thread

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 06:39 PM.


What Is My IP - IP Command Lines - What is an IP Address - Speed Test - IP Address FAQ

Need IP address location detection service? Get it from IP2Location.com now.

Powered by vBulletin®
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Copyright - WhatIsMyIP.com