Pure Programmer
Blue Matrix


Cluster Map

Project: Cubic Roots

Cubic equations of the form Ax3 + Bx2 + Cx + D = 0 have three possible solutions given by the [[Cubic Formula]]. Write a program that sets the constants A = 1, B = -6, C = 11 and D = -6 then prints the three possible solutions. Then change the constants A, B, C and D to get solutions to other quadratic equations. Is it possible that this program could fail?

Output
$ rustc CubicRoots.rs error[E0425]: cannot find value `PI` in this scope --> CubicRoots.rs:36:39 | 36 | let mut t2:f64 = a * cos(b - 2.f64 * PI / 3.f64); | ^^ not found in this scope | help: consider importing one of these items | 8 + use consts::PI; | 8 + use std::f32::consts::PI; | error[E0425]: cannot find value `PI` in this scope --> CubicRoots.rs:37:39 | 37 | let mut t3:f64 = a * cos(b - 4.f64 * PI / 3.f64); | ^^ not found in this scope | help: consider importing one of these items | 8 + use consts::PI; | 8 + use std::f32::consts::PI; | warning: unused import: `std::f64::consts` --> CubicRoots.rs:8:5 | 8 | use std::f64::consts; | ^^^^^^^^^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields --> CubicRoots.rs:23:21 | 23 | let mut p:f64 = (3.f64 * A * C - B * B) / (3.f64 * A * A); | ^^^ | help: if intended to be a floating point literal, consider adding a `0` after the period | 23 | let mut p:f64 = (3.0f64 * A * C - B * B) / (3.f64 * A * A); | + error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields --> CubicRoots.rs:23:47 | 23 | let mut p:f64 = (3.f64 * A * C - B * B) / (3.f64 * A * A); | ^^^ | help: if intended to be a floating point literal, consider adding a `0` after the period | 23 | let mut p:f64 = (3.f64 * A * C - B * B) / (3.0f64 * A * A); | + error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields --> CubicRoots.rs:24:21 | 24 | let mut q:f64 = (2.f64 * B * B * B - 9.f64 * A * B * C + 27.f64 * A * A * D) / (27.f64 * A * A * A); | ^^^ | help: if intended to be a floating point literal, consider adding a `0` after the period | 24 | let mut q:f64 = (2.0f64 * B * B * B - 9.f64 * A * B * C + 27.f64 * A * A * D) / (27.f64 * A * A * A); | + error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields --> CubicRoots.rs:24:41 | 24 | let mut q:f64 = (2.f64 * B * B * B - 9.f64 * A * B * C + 27.f64 * A * A * D) / (27.f64 * A * A * A); | ^^^ | help: if intended to be a floating point literal, consider adding a `0` after the period | 24 | let mut q:f64 = (2.f64 * B * B * B - 9.0f64 * A * B * C + 27.f64 * A * A * D) / (27.f64 * A * A * A); | + error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields --> CubicRoots.rs:24:62 | 24 | let mut q:f64 = (2.f64 * B * B * B - 9.f64 * A * B * C + 27.f64 * A * A * D) / (27.f64 * A * A * A); | ^^^ | help: if intended to be a floating point literal, consider adding a `0` after the period | 24 | let mut q:f64 = (2.f64 * B * B * B - 9.f64 * A * B * C + 27.0f64 * A * A * D) / (27.f64 * A * A * A); | + error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields --> CubicRoots.rs:24:85 | 24 | let mut q:f64 = (2.f64 * B * B * B - 9.f64 * A * B * C + 27.f64 * A * A * D) / (27.f64 * A * A * A); | ^^^ | help: if intended to be a floating point literal, consider adding a `0` after the period | 24 | let mut q:f64 = (2.f64 * B * B * B - 9.f64 * A * B * C + 27.f64 * A * A * D) / (27.0f64 * A * A * A); | + error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields --> CubicRoots.rs:32:20 | 32 | let mut a:f64 = 2.f64 * sqrt(-p / 3.f64); | ^^^ | help: if intended to be a floating point literal, consider adding a `0` after the period | 32 | let mut a:f64 = 2.0f64 * sqrt(-p / 3.f64); | + error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields --> CubicRoots.rs:32:38 | 32 | let mut a:f64 = 2.f64 * sqrt(-p / 3.f64); | ^^^ | help: if intended to be a floating point literal, consider adding a `0` after the period | 32 | let mut a:f64 = 2.f64 * sqrt(-p / 3.0f64); | + error[E0425]: cannot find function `sqrt` in this scope --> CubicRoots.rs:32:26 | 32 | let mut a:f64 = 2.f64 * sqrt(-p / 3.f64); | ^^^^ not found in this scope error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields --> CubicRoots.rs:33:21 | 33 | let mut b:f64 = (1.f64 / 3.f64) * acos(3.f64 * q / 2.f64 / p * sqrt(-3.f64 / p)); | ^^^ | help: if intended to be a floating point literal, consider adding a `0` after the period | 33 | let mut b:f64 = (1.0f64 / 3.f64) * acos(3.f64 * q / 2.f64 / p * sqrt(-3.f64 / p)); | + error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields --> CubicRoots.rs:33:29 | 33 | let mut b:f64 = (1.f64 / 3.f64) * acos(3.f64 * q / 2.f64 / p * sqrt(-3.f64 / p)); | ^^^ | help: if intended to be a floating point literal, consider adding a `0` after the period | 33 | let mut b:f64 = (1.f64 / 3.0f64) * acos(3.f64 * q / 2.f64 / p * sqrt(-3.f64 / p)); | + error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields --> CubicRoots.rs:33:43 | 33 | let mut b:f64 = (1.f64 / 3.f64) * acos(3.f64 * q / 2.f64 / p * sqrt(-3.f64 / p)); | ^^^ | help: if intended to be a floating point literal, consider adding a `0` after the period | 33 | let mut b:f64 = (1.f64 / 3.f64) * acos(3.0f64 * q / 2.f64 / p * sqrt(-3.f64 / p)); | + error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields --> CubicRoots.rs:33:55 | 33 | let mut b:f64 = (1.f64 / 3.f64) * acos(3.f64 * q / 2.f64 / p * sqrt(-3.f64 / p)); | ^^^ | help: if intended to be a floating point literal, consider adding a `0` after the period | 33 | let mut b:f64 = (1.f64 / 3.f64) * acos(3.f64 * q / 2.0f64 / p * sqrt(-3.f64 / p)); | + error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields --> CubicRoots.rs:33:73 | 33 | let mut b:f64 = (1.f64 / 3.f64) * acos(3.f64 * q / 2.f64 / p * sqrt(-3.f64 / p)); | ^^^ | help: if intended to be a floating point literal, consider adding a `0` after the period | 33 | let mut b:f64 = (1.f64 / 3.f64) * acos(3.f64 * q / 2.f64 / p * sqrt(-3.0f64 / p)); | + error[E0425]: cannot find function `sqrt` in this scope --> CubicRoots.rs:33:65 | 33 | let mut b:f64 = (1.f64 / 3.f64) * acos(3.f64 * q / 2.f64 / p * sqrt(-3.f64 / p)); | ^^^^ not found in this scope error[E0425]: cannot find function `acos` in this scope --> CubicRoots.rs:33:36 | 33 | let mut b:f64 = (1.f64 / 3.f64) * acos(3.f64 * q / 2.f64 / p * sqrt(-3.f64 / p)); | ^^^^ not found in this scope error[E0425]: cannot find function `cos` in this scope --> CubicRoots.rs:35:23 | 35 | let mut t1:f64 = a * cos(b); | ^^^ not found in this scope error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields --> CubicRoots.rs:36:33 | 36 | let mut t2:f64 = a * cos(b - 2.f64 * PI / 3.f64); | ^^^ | help: if intended to be a floating point literal, consider adding a `0` after the period | 36 | let mut t2:f64 = a * cos(b - 2.0f64 * PI / 3.f64); | + error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields --> CubicRoots.rs:36:46 | 36 | let mut t2:f64 = a * cos(b - 2.f64 * PI / 3.f64); | ^^^ | help: if intended to be a floating point literal, consider adding a `0` after the period | 36 | let mut t2:f64 = a * cos(b - 2.f64 * PI / 3.0f64); | + error[E0425]: cannot find function `cos` in this scope --> CubicRoots.rs:36:23 | 36 | let mut t2:f64 = a * cos(b - 2.f64 * PI / 3.f64); | ^^^ not found in this scope error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields --> CubicRoots.rs:37:33 | 37 | let mut t3:f64 = a * cos(b - 4.f64 * PI / 3.f64); | ^^^ | help: if intended to be a floating point literal, consider adding a `0` after the period | 37 | let mut t3:f64 = a * cos(b - 4.0f64 * PI / 3.f64); | + error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields --> CubicRoots.rs:37:46 | 37 | let mut t3:f64 = a * cos(b - 4.f64 * PI / 3.f64); | ^^^ | help: if intended to be a floating point literal, consider adding a `0` after the period | 37 | let mut t3:f64 = a * cos(b - 4.f64 * PI / 3.0f64); | + error[E0425]: cannot find function `cos` in this scope --> CubicRoots.rs:37:23 | 37 | let mut t3:f64 = a * cos(b - 4.f64 * PI / 3.f64); | ^^^ not found in this scope error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields --> CubicRoots.rs:38:34 | 38 | let mut root1:f64 = t1 - B / (3.f64 * A); | ^^^ | help: if intended to be a floating point literal, consider adding a `0` after the period | 38 | let mut root1:f64 = t1 - B / (3.0f64 * A); | + error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields --> CubicRoots.rs:39:34 | 39 | let mut root2:f64 = t2 - B / (3.f64 * A); | ^^^ | help: if intended to be a floating point literal, consider adding a `0` after the period | 39 | let mut root2:f64 = t2 - B / (3.0f64 * A); | + error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields --> CubicRoots.rs:40:34 | 40 | let mut root3:f64 = t3 - B / (3.f64 * A); | ^^^ | help: if intended to be a floating point literal, consider adding a `0` after the period | 40 | let mut root3:f64 = t3 - B / (3.0f64 * A); | + error: aborting due to 28 previous errors; 1 warning emitted Some errors have detailed explanations: E0425, E0610. For more information about an error, try `rustc --explain E0425`.

Solution