MCPcopy Create free account
hub / github.com/OpenSourcePhysics/osp / sqrt

Method sqrt

src/org/opensourcephysics/numerics/Complex.java:477–502  ·  view source on GitHub ↗

Calculates the square root of this object.

()

Source from the content-addressed store, hash-verified

475 * Calculates the square root of this object.
476 */
477 public Complex sqrt() {
478 Complex c;
479 double absRe, absIm, w, r;
480 if((re==0)&&(im==0)) {
481 c = new Complex(0, 0);
482 } else {
483 absRe = Math.abs(re);
484 absIm = Math.abs(im);
485 if(absRe>=absIm) {
486 r = absIm/absRe;
487 w = Math.sqrt(absRe)*Math.sqrt(0.5*(1.0+Math.sqrt(1.0+r*r)));
488 } else {
489 r = absRe/absIm;
490 w = Math.sqrt(absIm)*Math.sqrt(0.5*(r+Math.sqrt(1.0+r*r)));
491 }
492 if(re>=0) {
493 c = new Complex(w, im/(2.0*w));
494 } else {
495 if(im<0) {
496 w = -w;
497 }
498 c = new Complex(im/(2.0*w), w);
499 }
500 }
501 return c;
502 }
503
504 //------------------------------------------------------------------------
505 // Trigonometric functions

Callers 15

asinMethod · 0.95
acosMethod · 0.95
asinhMethod · 0.95
acoshMethod · 0.95
twobytwoMethod · 0.95
Demo3D_3AppMethod · 0.80
drawMethod · 0.80
getStatisticsMethod · 0.80
fitMethod · 0.80
getUncertaintiesMethod · 0.80
getScratchParamsMethod · 0.80
setAllMethod · 0.80

Calls 1

absMethod · 0.80

Tested by 5

getCoordinateStringMethod · 0.64
dipoleMethod · 0.64
dipoleVectorMethod · 0.64
dipoleVectorFieldMethod · 0.64