45 lines
829 B
Plaintext
45 lines
829 B
Plaintext
package main;
|
|
|
|
import (
|
|
"fmt";
|
|
"log";
|
|
)
|
|
|
|
|
|
// A toy implementation of cube root using Newton's method.
|
|
func CubeRoot(x float64) float64 {
|
|
z := x/3; // Arbitrary initial value
|
|
for i := 0; i < 1e6; i++ {
|
|
prevz := z;
|
|
z -= (z*z*z-x) / (3*z*z);
|
|
if veryClose(z, prevz) {
|
|
return z;
|
|
}
|
|
}
|
|
// A million iterations has not converged; something is wrong.
|
|
panic(fmt.Sprintf("CubeRoot(%g) did not converge", x));
|
|
}
|
|
|
|
|
|
func test() {
|
|
z -= (z*z*z-x) / (3*z*z);
|
|
return "123";
|
|
}
|
|
|
|
func test(a int, b string) {
|
|
s := "123njda skjad";
|
|
a := 2;
|
|
return a + 1;
|
|
}
|
|
|
|
func main() {
|
|
|
|
var a int;
|
|
var c complex128 = 555.12i+1.123i;
|
|
|
|
a := 123+123e45 + 123.456 +123.456e-78+123i+123.456e10i;
|
|
|
|
a = 2+2*2-(1+10)+213i*2 - 2.123i - c;
|
|
a = a + 1;
|
|
a = a;
|
|
} |