Next / Previous / Index / ITC Help System / Publications / Site map / NM Tech homepage

A quadratic root function in Icon

Tech Computer Center logo

Here is the function used in the quadratic root solver program:

procedure Quadratic_Roots ( a, b, c )
#--
# Generates the real roots of ax^2+bx+c=0.  Depending on the sign
# of d = b^2 - 4*a*c, there are three cases:
#   1. d < 0: no real roots
#	2. d = 0: one root, -b/2*a
#	3. d > 0: two roots, (-b+sqrt(d))/2*a and (-b-sqrt(d))/2*a
#--
  local d	# Discriminant

  d  :=  b ^ 2 - 4.0 * a * c;		# Compute the discriminant

  if  d > 0  then
  { #-- Two roots
    suspend ( - b + sqrt ( d ) ) / ( 2.0 * a );
    suspend ( - b - sqrt ( d ) ) / ( 2.0 * a );
  } #-- Two roots
  else if  d = 0  then
    suspend  - b / ( 2.0 * a );

  fail;		# No more roots
end # -- quadratic.icn --

Next: Using the basic Icon types
See also: A tutorial for the Icon programming language
Previous: A quadratic root solver in Icon
Site map
Index: Keyword index to help pages
Help: New Mexico Tech Information Technology and Communications: Help System
ITC Publications
To report a problem: File a ticket
Send mail to the User consultant on duty or call them at 575-835-5437
Home: About New Mexico Tech

John Shipman, john@nmt.edu
Last updated: 1996/01/06 21:12:57 UT
URL: http://www.nmt.edu/tcc/help/lang/icon/quadfunc.html
QR two-dimensional bar code