pub struct DTrig { /* private fields */ }Expand description
Main struct through which trig functions are implemented.
Once this struct is initialized, it holds arrays with pre-baked trig functions. Trig functions are called as methods with the input as (i32 , i32) tuples with the first i32 representing the numerator an the second i32 representing the denominator.
The output is also a (i32 , i32) tuple with the first i32 representing the numerator and the second i32 representing the denominator. The output denominator will always be 1000.
§Example
use deterministic_trigonometry::DTrig;
fn main (){
let d_trig = DTrig::initialize();
let sine_of_pi_over_four = d_trig.sine((785,1000));
println!("The sine of 785/1000 radians is {}/{}.", sine_of_pi_over_four.0, sine_of_pi_over_four.1);
}Implementations§
Source§impl DTrig
impl DTrig
Sourcepub fn initialize() -> Self
pub fn initialize() -> Self
Initializes the Dtrig struct.
- Must be used before any other Dtrig functions are used.
- Writes the pre-baked trigonometry tables into RAM.
§Example
use deterministic_trigonometry::DTrig;
fn main (){
let d_trig = DTrig::initialize();
let sine_of_pi_over_three = d_trig.sine((1047,1000));
println!("The sine of 1047/1000 radians is {}/{}.", sine_of_pi_over_three.0, sine_of_pi_over_three.1);
}Examples found in repository?
6fn main() {
7 // This initializes the DTrig struct which writes the pre-baked trig tables into memory.
8 let d_trig = DTrig::initialize();
9
10 // This variable allows the main loop to exit.
11 let mut continue_running = true;
12
13 // This is the main loop
14 while continue_running == true {
15 println!("Welcome to the trigonometry calculator!");
16 println!("");
17
18 // This helper function takes a code for the trig function and the input value from the user.
19 let input_tuple = take_user_input();
20
21 // Just for visual spacing.
22 println!("");
23
24 // This stores a code for the trig function. 1: sine | 2: cosine | 3: tangent | 4: arcsine | 5: arccosine | 6: arctangent
25 let trig_function = input_tuple.0;
26
27 // This stores the input for the trig function.
28 let input_value = input_tuple.1;
29
30 // This converts the input value to a faction over 1000.
31 let fraction_tuple = ((input_value * 1000.0).round() as i32, 1000);
32
33 // This provides the result based on the trig function and input value.
34 match trig_function {
35 1 => {
36 println!("The answer is {}/{}", d_trig.sine(fraction_tuple).0, 1000);
37 }
38 2 => {
39 println!("The answer is {}/{}", d_trig.cosine(fraction_tuple).0, 1000);
40 }
41 3 => {
42 println!("The answer is {}/{}", d_trig.tangent(fraction_tuple).0, 1000);
43 }
44 4 => {
45 println!("The answer is {}/{}", d_trig.arcsine(fraction_tuple).0, 1000);
46 }
47 5 => {
48 println!("The answer is {}/{}", d_trig.arccosine(fraction_tuple).0, 1000);
49 }
50 6 => {
51 println!("The answer is {}/{}", d_trig.arctangent(fraction_tuple).0, 1000);
52 }
53 _ => {
54 println!("Input error. Please try again");
55 }
56 }
57
58 // This asks the user if they want to do another calculation.
59 continue_running = ask_continue_running();
60 }
61}Source§impl DTrig
impl DTrig
Sourcepub fn sine(&self, argument_fraction: (i32, i32)) -> (i32, i32)
pub fn sine(&self, argument_fraction: (i32, i32)) -> (i32, i32)
Calculates the sine of an angle in radians.
- The input tuple represents the angle as a numerator and denominator.
- The output tuple represents the sine result as a numerator and denominator.
- Most accurate between 0 and 2 PI with a factor of 1000 as denominator.
- See README for limitations on accuracy.
§Panics
- A zero as the input for the denominator.
§Example
use deterministic_trigonometry::DTrig;
fn main (){
let d_trig = DTrig::initialize();
let sine_of_pi_over_four = d_trig.sine((785,1000));
println!("The sine of 785/1000 radians is {}/{}.", sine_of_pi_over_four.0, sine_of_pi_over_four.1);
}Examples found in repository?
6fn main() {
7 // This initializes the DTrig struct which writes the pre-baked trig tables into memory.
8 let d_trig = DTrig::initialize();
9
10 // This variable allows the main loop to exit.
11 let mut continue_running = true;
12
13 // This is the main loop
14 while continue_running == true {
15 println!("Welcome to the trigonometry calculator!");
16 println!("");
17
18 // This helper function takes a code for the trig function and the input value from the user.
19 let input_tuple = take_user_input();
20
21 // Just for visual spacing.
22 println!("");
23
24 // This stores a code for the trig function. 1: sine | 2: cosine | 3: tangent | 4: arcsine | 5: arccosine | 6: arctangent
25 let trig_function = input_tuple.0;
26
27 // This stores the input for the trig function.
28 let input_value = input_tuple.1;
29
30 // This converts the input value to a faction over 1000.
31 let fraction_tuple = ((input_value * 1000.0).round() as i32, 1000);
32
33 // This provides the result based on the trig function and input value.
34 match trig_function {
35 1 => {
36 println!("The answer is {}/{}", d_trig.sine(fraction_tuple).0, 1000);
37 }
38 2 => {
39 println!("The answer is {}/{}", d_trig.cosine(fraction_tuple).0, 1000);
40 }
41 3 => {
42 println!("The answer is {}/{}", d_trig.tangent(fraction_tuple).0, 1000);
43 }
44 4 => {
45 println!("The answer is {}/{}", d_trig.arcsine(fraction_tuple).0, 1000);
46 }
47 5 => {
48 println!("The answer is {}/{}", d_trig.arccosine(fraction_tuple).0, 1000);
49 }
50 6 => {
51 println!("The answer is {}/{}", d_trig.arctangent(fraction_tuple).0, 1000);
52 }
53 _ => {
54 println!("Input error. Please try again");
55 }
56 }
57
58 // This asks the user if they want to do another calculation.
59 continue_running = ask_continue_running();
60 }
61}Sourcepub fn cosine(&self, argument_fraction: (i32, i32)) -> (i32, i32)
pub fn cosine(&self, argument_fraction: (i32, i32)) -> (i32, i32)
Calculates the cosine of an angle in radians.
- The input tuple represents the input angle as a numerator and denominator.
- The output tuple represents the cosine result as a numerator and denominator.
- Most accurate between 0 and 2 PI with a factor of 1000 as denominator.
- See README for limitations on accuracy.
§Panics
- A zero as the input for the denominator.
§Example
use deterministic_trigonometry::DTrig;
fn main (){
let d_trig = DTrig::initialize();
let cosine_of_pi_over_four = d_trig.cosine((785,1000));
println!("The cosine of 785/1000 radians is {}/{}.", cosine_of_pi_over_four.0, cosine_of_pi_over_four.1);
}
Examples found in repository?
6fn main() {
7 // This initializes the DTrig struct which writes the pre-baked trig tables into memory.
8 let d_trig = DTrig::initialize();
9
10 // This variable allows the main loop to exit.
11 let mut continue_running = true;
12
13 // This is the main loop
14 while continue_running == true {
15 println!("Welcome to the trigonometry calculator!");
16 println!("");
17
18 // This helper function takes a code for the trig function and the input value from the user.
19 let input_tuple = take_user_input();
20
21 // Just for visual spacing.
22 println!("");
23
24 // This stores a code for the trig function. 1: sine | 2: cosine | 3: tangent | 4: arcsine | 5: arccosine | 6: arctangent
25 let trig_function = input_tuple.0;
26
27 // This stores the input for the trig function.
28 let input_value = input_tuple.1;
29
30 // This converts the input value to a faction over 1000.
31 let fraction_tuple = ((input_value * 1000.0).round() as i32, 1000);
32
33 // This provides the result based on the trig function and input value.
34 match trig_function {
35 1 => {
36 println!("The answer is {}/{}", d_trig.sine(fraction_tuple).0, 1000);
37 }
38 2 => {
39 println!("The answer is {}/{}", d_trig.cosine(fraction_tuple).0, 1000);
40 }
41 3 => {
42 println!("The answer is {}/{}", d_trig.tangent(fraction_tuple).0, 1000);
43 }
44 4 => {
45 println!("The answer is {}/{}", d_trig.arcsine(fraction_tuple).0, 1000);
46 }
47 5 => {
48 println!("The answer is {}/{}", d_trig.arccosine(fraction_tuple).0, 1000);
49 }
50 6 => {
51 println!("The answer is {}/{}", d_trig.arctangent(fraction_tuple).0, 1000);
52 }
53 _ => {
54 println!("Input error. Please try again");
55 }
56 }
57
58 // This asks the user if they want to do another calculation.
59 continue_running = ask_continue_running();
60 }
61}Sourcepub fn tangent(&self, argument_fraction: (i32, i32)) -> (i32, i32)
pub fn tangent(&self, argument_fraction: (i32, i32)) -> (i32, i32)
Calculates the tangent of an angle in radians.
- The input tuple represents the input angle as a numerator and denominator.
- The output tuple represents the tangent result as a numerator and denominator.
- Most accurate between 0 and 2 PI with a factor of 1000 as denominator.
- Can have large errors around asymptote lines for the tangent function.
- See README for limitations on accuracy.
§Panics
- A zero as the input for the denominator.
§Example
use deterministic_trigonometry::DTrig;
fn main (){
let d_trig = DTrig::initialize();
let tangent_of_pi_over_four = d_trig.tangent((785,1000));
println!("The tangent of 785/1000 radians is {}/{}.", tangent_of_pi_over_four.0, tangent_of_pi_over_four.1);
}Examples found in repository?
6fn main() {
7 // This initializes the DTrig struct which writes the pre-baked trig tables into memory.
8 let d_trig = DTrig::initialize();
9
10 // This variable allows the main loop to exit.
11 let mut continue_running = true;
12
13 // This is the main loop
14 while continue_running == true {
15 println!("Welcome to the trigonometry calculator!");
16 println!("");
17
18 // This helper function takes a code for the trig function and the input value from the user.
19 let input_tuple = take_user_input();
20
21 // Just for visual spacing.
22 println!("");
23
24 // This stores a code for the trig function. 1: sine | 2: cosine | 3: tangent | 4: arcsine | 5: arccosine | 6: arctangent
25 let trig_function = input_tuple.0;
26
27 // This stores the input for the trig function.
28 let input_value = input_tuple.1;
29
30 // This converts the input value to a faction over 1000.
31 let fraction_tuple = ((input_value * 1000.0).round() as i32, 1000);
32
33 // This provides the result based on the trig function and input value.
34 match trig_function {
35 1 => {
36 println!("The answer is {}/{}", d_trig.sine(fraction_tuple).0, 1000);
37 }
38 2 => {
39 println!("The answer is {}/{}", d_trig.cosine(fraction_tuple).0, 1000);
40 }
41 3 => {
42 println!("The answer is {}/{}", d_trig.tangent(fraction_tuple).0, 1000);
43 }
44 4 => {
45 println!("The answer is {}/{}", d_trig.arcsine(fraction_tuple).0, 1000);
46 }
47 5 => {
48 println!("The answer is {}/{}", d_trig.arccosine(fraction_tuple).0, 1000);
49 }
50 6 => {
51 println!("The answer is {}/{}", d_trig.arctangent(fraction_tuple).0, 1000);
52 }
53 _ => {
54 println!("Input error. Please try again");
55 }
56 }
57
58 // This asks the user if they want to do another calculation.
59 continue_running = ask_continue_running();
60 }
61}Sourcepub fn arcsine(&self, argument_fraction: (i32, i32)) -> (i32, i32)
pub fn arcsine(&self, argument_fraction: (i32, i32)) -> (i32, i32)
Performs arcsine on a value to produce the measure of the corresponding angle in radians.
- The input tuple represents the input value as a numerator and denominator.
- The output tuple represents the angle result in radians as a numerator and denominator.
- Most accurate with a factor of 1000 as denominator.
- See README for detailed limitations on accuracy.
§Panics
- A zero as the input for the denominator.
- Inputs representing a fractions with a value greater than 1 or less than -1.
- This is out of the mathematically defined denominator the arcsine function.
§Example
use deterministic_trigonometry::DTrig;
fn main (){
let d_trig = DTrig::initialize();
let arcsine_of_one_half = d_trig.arcsine((500,1000));
println!("The arcsine of 500/1000 radians is {}/{}.", arcsine_of_one_half.0, arcsine_of_one_half.1);
}Examples found in repository?
6fn main() {
7 // This initializes the DTrig struct which writes the pre-baked trig tables into memory.
8 let d_trig = DTrig::initialize();
9
10 // This variable allows the main loop to exit.
11 let mut continue_running = true;
12
13 // This is the main loop
14 while continue_running == true {
15 println!("Welcome to the trigonometry calculator!");
16 println!("");
17
18 // This helper function takes a code for the trig function and the input value from the user.
19 let input_tuple = take_user_input();
20
21 // Just for visual spacing.
22 println!("");
23
24 // This stores a code for the trig function. 1: sine | 2: cosine | 3: tangent | 4: arcsine | 5: arccosine | 6: arctangent
25 let trig_function = input_tuple.0;
26
27 // This stores the input for the trig function.
28 let input_value = input_tuple.1;
29
30 // This converts the input value to a faction over 1000.
31 let fraction_tuple = ((input_value * 1000.0).round() as i32, 1000);
32
33 // This provides the result based on the trig function and input value.
34 match trig_function {
35 1 => {
36 println!("The answer is {}/{}", d_trig.sine(fraction_tuple).0, 1000);
37 }
38 2 => {
39 println!("The answer is {}/{}", d_trig.cosine(fraction_tuple).0, 1000);
40 }
41 3 => {
42 println!("The answer is {}/{}", d_trig.tangent(fraction_tuple).0, 1000);
43 }
44 4 => {
45 println!("The answer is {}/{}", d_trig.arcsine(fraction_tuple).0, 1000);
46 }
47 5 => {
48 println!("The answer is {}/{}", d_trig.arccosine(fraction_tuple).0, 1000);
49 }
50 6 => {
51 println!("The answer is {}/{}", d_trig.arctangent(fraction_tuple).0, 1000);
52 }
53 _ => {
54 println!("Input error. Please try again");
55 }
56 }
57
58 // This asks the user if they want to do another calculation.
59 continue_running = ask_continue_running();
60 }
61}Sourcepub fn arccosine(&self, argument_fraction: (i32, i32)) -> (i32, i32)
pub fn arccosine(&self, argument_fraction: (i32, i32)) -> (i32, i32)
Performs arccosine on a value to produce the measure of the corresponding angle in radians
- The input tuple represents the input value as a numerator and denominator.
- The output tuple represents the angle result in radians as a numerator and denominator.
- Most accurate with a factor of 1000 as denominator.
- See README for detailed limitations on accuracy.
§Panics
- A zero as the input for the denominator.
- Inputs representing a fractions with a value greater than 1 or less than -1.
- This is out of the mathematically defined domain for the arccosine function.
§Example
use deterministic_trigonometry::DTrig;
fn main (){
let d_trig = DTrig::initialize();
let arccosine_of_one_half = d_trig.arccosine((500,1000));
println!("The arccosine of 500/1000 radians is {}/{}.", arccosine_of_one_half.0, arccosine_of_one_half.1);
}Examples found in repository?
6fn main() {
7 // This initializes the DTrig struct which writes the pre-baked trig tables into memory.
8 let d_trig = DTrig::initialize();
9
10 // This variable allows the main loop to exit.
11 let mut continue_running = true;
12
13 // This is the main loop
14 while continue_running == true {
15 println!("Welcome to the trigonometry calculator!");
16 println!("");
17
18 // This helper function takes a code for the trig function and the input value from the user.
19 let input_tuple = take_user_input();
20
21 // Just for visual spacing.
22 println!("");
23
24 // This stores a code for the trig function. 1: sine | 2: cosine | 3: tangent | 4: arcsine | 5: arccosine | 6: arctangent
25 let trig_function = input_tuple.0;
26
27 // This stores the input for the trig function.
28 let input_value = input_tuple.1;
29
30 // This converts the input value to a faction over 1000.
31 let fraction_tuple = ((input_value * 1000.0).round() as i32, 1000);
32
33 // This provides the result based on the trig function and input value.
34 match trig_function {
35 1 => {
36 println!("The answer is {}/{}", d_trig.sine(fraction_tuple).0, 1000);
37 }
38 2 => {
39 println!("The answer is {}/{}", d_trig.cosine(fraction_tuple).0, 1000);
40 }
41 3 => {
42 println!("The answer is {}/{}", d_trig.tangent(fraction_tuple).0, 1000);
43 }
44 4 => {
45 println!("The answer is {}/{}", d_trig.arcsine(fraction_tuple).0, 1000);
46 }
47 5 => {
48 println!("The answer is {}/{}", d_trig.arccosine(fraction_tuple).0, 1000);
49 }
50 6 => {
51 println!("The answer is {}/{}", d_trig.arctangent(fraction_tuple).0, 1000);
52 }
53 _ => {
54 println!("Input error. Please try again");
55 }
56 }
57
58 // This asks the user if they want to do another calculation.
59 continue_running = ask_continue_running();
60 }
61}Sourcepub fn arctangent(&self, argument_fraction: (i32, i32)) -> (i32, i32)
pub fn arctangent(&self, argument_fraction: (i32, i32)) -> (i32, i32)
Performs arctangent on a value to produce the measure of the corresponding angle in radians
- The input tuple represents the input value as a numerator and denominator.
- The output tuple represents the angle result in radians as a numerator and denominator.
- Most accurate with a factor of 1000 as denominator.
- See README for detailed limitations on accuracy.
§Panics
- A zero as the input for the denominator.
§Example
use deterministic_trigonometry::DTrig;
fn main (){
let d_trig = DTrig::initialize();
let arctangent_of_one_half = d_trig.arctangent((500,1000));
println!("The arctangent of 500/1000 radians is {}/{}.", arctangent_of_one_half.0, arctangent_of_one_half.1);
}
Examples found in repository?
6fn main() {
7 // This initializes the DTrig struct which writes the pre-baked trig tables into memory.
8 let d_trig = DTrig::initialize();
9
10 // This variable allows the main loop to exit.
11 let mut continue_running = true;
12
13 // This is the main loop
14 while continue_running == true {
15 println!("Welcome to the trigonometry calculator!");
16 println!("");
17
18 // This helper function takes a code for the trig function and the input value from the user.
19 let input_tuple = take_user_input();
20
21 // Just for visual spacing.
22 println!("");
23
24 // This stores a code for the trig function. 1: sine | 2: cosine | 3: tangent | 4: arcsine | 5: arccosine | 6: arctangent
25 let trig_function = input_tuple.0;
26
27 // This stores the input for the trig function.
28 let input_value = input_tuple.1;
29
30 // This converts the input value to a faction over 1000.
31 let fraction_tuple = ((input_value * 1000.0).round() as i32, 1000);
32
33 // This provides the result based on the trig function and input value.
34 match trig_function {
35 1 => {
36 println!("The answer is {}/{}", d_trig.sine(fraction_tuple).0, 1000);
37 }
38 2 => {
39 println!("The answer is {}/{}", d_trig.cosine(fraction_tuple).0, 1000);
40 }
41 3 => {
42 println!("The answer is {}/{}", d_trig.tangent(fraction_tuple).0, 1000);
43 }
44 4 => {
45 println!("The answer is {}/{}", d_trig.arcsine(fraction_tuple).0, 1000);
46 }
47 5 => {
48 println!("The answer is {}/{}", d_trig.arccosine(fraction_tuple).0, 1000);
49 }
50 6 => {
51 println!("The answer is {}/{}", d_trig.arctangent(fraction_tuple).0, 1000);
52 }
53 _ => {
54 println!("Input error. Please try again");
55 }
56 }
57
58 // This asks the user if they want to do another calculation.
59 continue_running = ask_continue_running();
60 }
61}