Arithmetic/Complex: Difference between revisions

Arithmetic/Complex en BASIC - añadidas la conjugación compleja, resta y división
(Added Arturo implementation)
(Arithmetic/Complex en BASIC - añadidas la conjugación compleja, resta y división)
Line 284:
imag AS DOUBLE
END TYPE
 
DECLARE SUB addsuma (a AS complex, b AS complex, c AS complex)
DECLARE SUB rest (a AS complex, b AS complex, c AS complex)
DECLARE SUB mult (a AS complex, b AS complex, c AS complex)
DECLARE SUB invdivi (a AS complex, b AS complex, c AS complex)
DECLARE SUB neg (a AS complex, b AS complex)
DECLARE SUB inv (a AS complex, b AS complex)
DECLARE SUB conj (a AS complex, b AS complex)
 
CLS
DIM x AS complex
Line 296 ⟶ 301:
y.real = 2
y.imag = 2
 
CALL add(x, y, z)
PRINT z"Siendo x = "; x.real; "+"; zx.imag; "i"
PRINT " e y = "; y.real; "+"; y.imag; "i"
PRINT
CALL addsuma(x, y, z)
PRINT "x + y = "; z.real; "+"; z.imag; "i"
CALL rest(x, y, z)
PRINT "x - y = "; z.real; "+"; z.imag; "i"
CALL mult(x, y, z)
PRINT "x * y = "; z.real; "+"; z.imag; "i"
CALL invdivi(x, y, z)
PRINT "x / y = "; z.real; "+"; z.imag; "i"
CALL neg(x, z)
PRINT " -x = "; z.real; "+"; z.imag; "i"
CALL inv(x, z)
 
PRINT "1 / x = "; z.real; "+"; z.imag; "i"
CALL conj(x, z)
PRINT " x* = "; z.real; "+"; z.imag; "i"
END
 
SUB addsuma (a AS complex, b AS complex, c AS complex)
c.real = a.real + b.real
c.imag = a.imag + b.imag
Line 325 ⟶ 340:
b.real = -a.real
b.imag = -a.imag
END SUB</lang>
 
SUB conj (a AS complex, b AS complex)
b.real = a.real
b.imag = -a.imag
END SUB
 
SUB divi (a AS complex, b AS complex, c AS complex)
c.real = ((a.real * b.real + b.imag * a.imag) / (b.real ^ 2 + b.imag ^ 2))
c.imag = ((a.imag * b.real - a.real * b.imag) / (b.real ^ 2 + b.imag ^ 2))
END SUB
 
SUB rest (a AS complex, b AS complex, c AS complex)
c.real = a.real - b.real
c.imag = a.imag - b.imag
END SUB
</lang>
{{out}}
<pre>Siendo 3x += 3 i1+ 3i
e y = 5+ 2i
0 + 4 i
 
.5 +-.5 i
x + y = 6 + 5 i
-1 +-1 i</pre>
x - y = -4 + 1 i
x * y = -1 + 17 i
x / y = .3793103448275862 + .4482758620689655 i
-x = -1 +-3 i
1 / x = .1 +-.3 i
- x* = 1 +-13 i</pre>
 
=={{header|BBC BASIC}}==
2,122

edits