This is a basic quadratic calculator that will give you the roots of a quadratic equation. The output is given in both Radical format and Approximate format (which will actually be exact if the solution is rational, and which will be replaced by NONREAL if it involes non-real numbers), or a nullset if there are no roots.**/quadcalc** will open the dialog.

I appologize for the ugliness of the dialog; I originally intended it for my own purposes then later decided to submit it here and didn't feel like redoing the dialog. Maybe I'll get around to it sometime.

--CANT BELIEVE THERES ANOTHER EDIT--

Fixed error where output fields did not clear on consecutive evaluations

```
dialog quad {
title "Quadratic Calculator"
size -1 -1 169 144
option dbu
edit "", 1, 2 17 16 10, autohs
text "Quadratic Calculator", 2, 0 2 168 8, center
text "x^2+", 3, 19 18 16 8
edit "", 4, 35 17 16 10, autohs
text "x+", 5, 51 18 8 8
edit "", 6, 59 17 16 10, autohs
text "=0", 7, 75 18 10 8
button "Evaluate", 9, 130 36 37 12, default
check "Round", 8, 3 31 29 10
box "Float Options", 10, 12 40 111 25, disable
radio "Floor", 12, 15 48 25 10, disable group
radio "Ceiling", 11, 40 48 29 10, disable
radio "To", 13, 70 48 16 10, disable
edit "", 14, 87 48 12 10, limit 2
text "th digit", 15, 100 49 20 8, disable
text "Radical", 16, 3 78 20 8
edit "", 18, 24 77 93 10, read
text "Approx", 19, 3 108 20 8
edit "", 20, 24 101 93 10, read
button "OK", 21, 70 129 37 12, flat ok
edit "", 40, 24 111 93 10, read
}
alias quadcalc {
dialog -rm quad quad
}
on *:DIALOG:quad:init:0: {
did -a quad 1 1
did -a quad 4 1
did -a quad 6 0
did -m quad 14
}
on *:DIALOG:quad:sclick:9,8,13,11,12: {
if ( $did == 9 ) {
did -r quad 20
did -r quad 18
did -r quad 40
var %a = $did(quad,1)
var %b = $did(quad,4)
var %c = $did(quad,6)
var %nump = $calc(%b ^ 2 - ( 4 * %a * %c ))
did -a quad 18 $calc(-1 * %b)) $chr(177) $+(SQRT,$chr(40),%nump,$chr(41)) / $calc(2 * %a)
if ( %nump == 0 ) {
did -a quad 20 0
did -a quad 40 $chr(216)
halt
}
if ( $did(quad,8).state == 1 ) {
if ( $did(quad,11).state == 1 ) {
did -a quad 20 $floor($calc((-1 * %b) + $sqrt(%nump) / (2 * %a)))
did -a quad 40 $floor($calc((-1 * %b) - $sqrt(%nump) / (2 * %a)))
var %c = 1
}
elseif ( $did(quad,12).state == 1 ) {
did -a quad 20 $ceil($calc((-1 * %b) + $sqrt(%nump) / (2 * %a)))
did -a quad 40 $ceil($calc((-1 * %b) - $sqrt(%nump) / (2 * %a)))
var %c = 1
}
elseif ( $did(quad,13).state == 1 ) {
did -a quad 20 $round($calc((-1 * %b) + $sqrt(%nump) / (2 * %a)),$iif($did(quad,14),$did(quad,14),1))
did -a quad 40 $round($calc((-1 * %b) - $sqrt(%nump) / (2 * %a)),$iif($did(quad,14),$did(quad,14),1))
var %c = 1
}
}
if ( !%c ) {
did -a quad 20 $calc((-1 * %b) + $sqrt(%nump) / (2 * %a))
did -a quad 40 $calc((-1 * %b) - $sqrt(%nump) / (2 * %a))
}
.timerf 1 0.1 chd %nump
}
elseif ( $did == 8 ) {
if ( $did(quad,8).state == 1 ) {
did -be quad 11,12,13,10
did -c quad 12
did -u quad 13
did -u quad 11
}
else {
did -b quad 11
did -b quad 12
did -b quad 13
did -b quad 15
did -b quad 10
did -m quad 14
}
}
elseif ( $did == 13 ) {
if ( $did(quad,13).state == 1 ) {
did -n quad 14
did -e quad 15
}
else {
did -m quad 14
did -b quad 15
}
}
else {
did -m quad 14
did -b quad 15
}
}
alias -l chd {
if ( !$did(quad,20) ) {
if ( $left($1,1) != - ) {
did -a quad 20 NONREAL
did -a quad 40 NONREAL
}
else {
did -a quad 20 $chr(216)
did -a quad 40 $chr(216)
}
}
}
```

Sign in to comment.

Are you sure you want to unfollow this person?

Are you sure you want to delete this?

Click "Unsubscribe" to stop receiving notices pertaining to this post.

Click "Subscribe" to resume notices pertaining to this post.