Quadratic Calculator

Platform:  mIRC
Published  Apr 28, 2005
Updated  Aug 23, 2005
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.<BR><B>/quadcalc</B> will open the dialog.<BR>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.<BR>--CANT BELIEVE THERES ANOTHER EDIT--<BR>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)
}
}
}

Comments

Sign in to comment.
MoNoXiDe   -  Dec 19, 2007
Hey nice work, I did 10x^2 - 17x + 3 but it didn\'t give me the right answer.

The radical was 17 ± SQRT(169) / 20 when it should be (17 ± SQRT(169)) / 20.
 Respond  
LIQUID_NiTrO   -  May 10, 2005
If anyone has any idea as to how the editboxes with the answers change from read-only to disabled when you click Evaluate I\'d be glad to know as I have looked through the code a thousand times and can\'t figure out why
 Respond  
log2   -  May 01, 2005
oops I used: 1, -5, -2 not: 1, 5, -2... they would be switched around the other way... x1 = -5.3723, x2 = 0.3723
 Respond  
log2   -  May 01, 2005
It doesn\'t work correctly... I tried doing some calculations with it, like 1, 5, -2... so the equation would be: -5 +/- (sqrt)5^2 - 4 (1)(-2) wich gives you two roots: x1 = 5.3723 and x2 = -0.3723... When I did it in your calc, I got: NONREAL and NONREAL
 Respond  
Ripp0n   -  May 01, 2005
good job Liquid
 Respond  
Relinsquish   -  Apr 29, 2005
The /did commands that use the same switches and parameters can combine dialog ids together with commas. For example, did -b quad 11 | did -b quad 12 | did -b quad 13, can be shortened to: did -b quad 11,12,13
 Respond  
DarthReven   -  Apr 28, 2005
very nice Liquid
 Respond  
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.