Struct deterministic_trigonometry::DTrig
source · 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?
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
fn main() {
// This initializes the DTrig struct which writes the pre-baked trig tables into memory.
let d_trig = DTrig::initialize();
// This variable allows the main loop to exit.
let mut continue_running = true;
// This is the main loop
while continue_running == true {
println!("Welcome to the trigonometry calculator!");
println!("");
// This helper function takes a code for the trig function and the input value from the user.
let input_tuple = take_user_input();
// Just for visual spacing.
println!("");
// This stores a code for the trig function. 1: sine | 2: cosine | 3: tangent | 4: arcsine | 5: arccosine | 6: arctangent
let trig_function = input_tuple.0;
// This stores the input for the trig function.
let input_value = input_tuple.1;
// This converts the input value to a faction over 1000.
let fraction_tuple = ((input_value * 1000.0).round() as i32, 1000);
// This provides the result based on the trig function and input value.
match trig_function {
1 => {
println!("The answer is {}/{}", d_trig.sine(fraction_tuple).0, 1000);
}
2 => {
println!("The answer is {}/{}", d_trig.cosine(fraction_tuple).0, 1000);
}
3 => {
println!("The answer is {}/{}", d_trig.tangent(fraction_tuple).0, 1000);
}
4 => {
println!("The answer is {}/{}", d_trig.arcsine(fraction_tuple).0, 1000);
}
5 => {
println!("The answer is {}/{}", d_trig.arccosine(fraction_tuple).0, 1000);
}
6 => {
println!("The answer is {}/{}", d_trig.arctangent(fraction_tuple).0, 1000);
}
_ => {
println!("Input error. Please try again");
}
}
// This asks the user if they want to do another calculation.
continue_running = ask_continue_running();
}
}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?
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
fn main() {
// This initializes the DTrig struct which writes the pre-baked trig tables into memory.
let d_trig = DTrig::initialize();
// This variable allows the main loop to exit.
let mut continue_running = true;
// This is the main loop
while continue_running == true {
println!("Welcome to the trigonometry calculator!");
println!("");
// This helper function takes a code for the trig function and the input value from the user.
let input_tuple = take_user_input();
// Just for visual spacing.
println!("");
// This stores a code for the trig function. 1: sine | 2: cosine | 3: tangent | 4: arcsine | 5: arccosine | 6: arctangent
let trig_function = input_tuple.0;
// This stores the input for the trig function.
let input_value = input_tuple.1;
// This converts the input value to a faction over 1000.
let fraction_tuple = ((input_value * 1000.0).round() as i32, 1000);
// This provides the result based on the trig function and input value.
match trig_function {
1 => {
println!("The answer is {}/{}", d_trig.sine(fraction_tuple).0, 1000);
}
2 => {
println!("The answer is {}/{}", d_trig.cosine(fraction_tuple).0, 1000);
}
3 => {
println!("The answer is {}/{}", d_trig.tangent(fraction_tuple).0, 1000);
}
4 => {
println!("The answer is {}/{}", d_trig.arcsine(fraction_tuple).0, 1000);
}
5 => {
println!("The answer is {}/{}", d_trig.arccosine(fraction_tuple).0, 1000);
}
6 => {
println!("The answer is {}/{}", d_trig.arctangent(fraction_tuple).0, 1000);
}
_ => {
println!("Input error. Please try again");
}
}
// This asks the user if they want to do another calculation.
continue_running = ask_continue_running();
}
}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?
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
fn main() {
// This initializes the DTrig struct which writes the pre-baked trig tables into memory.
let d_trig = DTrig::initialize();
// This variable allows the main loop to exit.
let mut continue_running = true;
// This is the main loop
while continue_running == true {
println!("Welcome to the trigonometry calculator!");
println!("");
// This helper function takes a code for the trig function and the input value from the user.
let input_tuple = take_user_input();
// Just for visual spacing.
println!("");
// This stores a code for the trig function. 1: sine | 2: cosine | 3: tangent | 4: arcsine | 5: arccosine | 6: arctangent
let trig_function = input_tuple.0;
// This stores the input for the trig function.
let input_value = input_tuple.1;
// This converts the input value to a faction over 1000.
let fraction_tuple = ((input_value * 1000.0).round() as i32, 1000);
// This provides the result based on the trig function and input value.
match trig_function {
1 => {
println!("The answer is {}/{}", d_trig.sine(fraction_tuple).0, 1000);
}
2 => {
println!("The answer is {}/{}", d_trig.cosine(fraction_tuple).0, 1000);
}
3 => {
println!("The answer is {}/{}", d_trig.tangent(fraction_tuple).0, 1000);
}
4 => {
println!("The answer is {}/{}", d_trig.arcsine(fraction_tuple).0, 1000);
}
5 => {
println!("The answer is {}/{}", d_trig.arccosine(fraction_tuple).0, 1000);
}
6 => {
println!("The answer is {}/{}", d_trig.arctangent(fraction_tuple).0, 1000);
}
_ => {
println!("Input error. Please try again");
}
}
// This asks the user if they want to do another calculation.
continue_running = ask_continue_running();
}
}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?
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
fn main() {
// This initializes the DTrig struct which writes the pre-baked trig tables into memory.
let d_trig = DTrig::initialize();
// This variable allows the main loop to exit.
let mut continue_running = true;
// This is the main loop
while continue_running == true {
println!("Welcome to the trigonometry calculator!");
println!("");
// This helper function takes a code for the trig function and the input value from the user.
let input_tuple = take_user_input();
// Just for visual spacing.
println!("");
// This stores a code for the trig function. 1: sine | 2: cosine | 3: tangent | 4: arcsine | 5: arccosine | 6: arctangent
let trig_function = input_tuple.0;
// This stores the input for the trig function.
let input_value = input_tuple.1;
// This converts the input value to a faction over 1000.
let fraction_tuple = ((input_value * 1000.0).round() as i32, 1000);
// This provides the result based on the trig function and input value.
match trig_function {
1 => {
println!("The answer is {}/{}", d_trig.sine(fraction_tuple).0, 1000);
}
2 => {
println!("The answer is {}/{}", d_trig.cosine(fraction_tuple).0, 1000);
}
3 => {
println!("The answer is {}/{}", d_trig.tangent(fraction_tuple).0, 1000);
}
4 => {
println!("The answer is {}/{}", d_trig.arcsine(fraction_tuple).0, 1000);
}
5 => {
println!("The answer is {}/{}", d_trig.arccosine(fraction_tuple).0, 1000);
}
6 => {
println!("The answer is {}/{}", d_trig.arctangent(fraction_tuple).0, 1000);
}
_ => {
println!("Input error. Please try again");
}
}
// This asks the user if they want to do another calculation.
continue_running = ask_continue_running();
}
}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?
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
fn main() {
// This initializes the DTrig struct which writes the pre-baked trig tables into memory.
let d_trig = DTrig::initialize();
// This variable allows the main loop to exit.
let mut continue_running = true;
// This is the main loop
while continue_running == true {
println!("Welcome to the trigonometry calculator!");
println!("");
// This helper function takes a code for the trig function and the input value from the user.
let input_tuple = take_user_input();
// Just for visual spacing.
println!("");
// This stores a code for the trig function. 1: sine | 2: cosine | 3: tangent | 4: arcsine | 5: arccosine | 6: arctangent
let trig_function = input_tuple.0;
// This stores the input for the trig function.
let input_value = input_tuple.1;
// This converts the input value to a faction over 1000.
let fraction_tuple = ((input_value * 1000.0).round() as i32, 1000);
// This provides the result based on the trig function and input value.
match trig_function {
1 => {
println!("The answer is {}/{}", d_trig.sine(fraction_tuple).0, 1000);
}
2 => {
println!("The answer is {}/{}", d_trig.cosine(fraction_tuple).0, 1000);
}
3 => {
println!("The answer is {}/{}", d_trig.tangent(fraction_tuple).0, 1000);
}
4 => {
println!("The answer is {}/{}", d_trig.arcsine(fraction_tuple).0, 1000);
}
5 => {
println!("The answer is {}/{}", d_trig.arccosine(fraction_tuple).0, 1000);
}
6 => {
println!("The answer is {}/{}", d_trig.arctangent(fraction_tuple).0, 1000);
}
_ => {
println!("Input error. Please try again");
}
}
// This asks the user if they want to do another calculation.
continue_running = ask_continue_running();
}
}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?
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
fn main() {
// This initializes the DTrig struct which writes the pre-baked trig tables into memory.
let d_trig = DTrig::initialize();
// This variable allows the main loop to exit.
let mut continue_running = true;
// This is the main loop
while continue_running == true {
println!("Welcome to the trigonometry calculator!");
println!("");
// This helper function takes a code for the trig function and the input value from the user.
let input_tuple = take_user_input();
// Just for visual spacing.
println!("");
// This stores a code for the trig function. 1: sine | 2: cosine | 3: tangent | 4: arcsine | 5: arccosine | 6: arctangent
let trig_function = input_tuple.0;
// This stores the input for the trig function.
let input_value = input_tuple.1;
// This converts the input value to a faction over 1000.
let fraction_tuple = ((input_value * 1000.0).round() as i32, 1000);
// This provides the result based on the trig function and input value.
match trig_function {
1 => {
println!("The answer is {}/{}", d_trig.sine(fraction_tuple).0, 1000);
}
2 => {
println!("The answer is {}/{}", d_trig.cosine(fraction_tuple).0, 1000);
}
3 => {
println!("The answer is {}/{}", d_trig.tangent(fraction_tuple).0, 1000);
}
4 => {
println!("The answer is {}/{}", d_trig.arcsine(fraction_tuple).0, 1000);
}
5 => {
println!("The answer is {}/{}", d_trig.arccosine(fraction_tuple).0, 1000);
}
6 => {
println!("The answer is {}/{}", d_trig.arctangent(fraction_tuple).0, 1000);
}
_ => {
println!("Input error. Please try again");
}
}
// This asks the user if they want to do another calculation.
continue_running = ask_continue_running();
}
}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?
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
fn main() {
// This initializes the DTrig struct which writes the pre-baked trig tables into memory.
let d_trig = DTrig::initialize();
// This variable allows the main loop to exit.
let mut continue_running = true;
// This is the main loop
while continue_running == true {
println!("Welcome to the trigonometry calculator!");
println!("");
// This helper function takes a code for the trig function and the input value from the user.
let input_tuple = take_user_input();
// Just for visual spacing.
println!("");
// This stores a code for the trig function. 1: sine | 2: cosine | 3: tangent | 4: arcsine | 5: arccosine | 6: arctangent
let trig_function = input_tuple.0;
// This stores the input for the trig function.
let input_value = input_tuple.1;
// This converts the input value to a faction over 1000.
let fraction_tuple = ((input_value * 1000.0).round() as i32, 1000);
// This provides the result based on the trig function and input value.
match trig_function {
1 => {
println!("The answer is {}/{}", d_trig.sine(fraction_tuple).0, 1000);
}
2 => {
println!("The answer is {}/{}", d_trig.cosine(fraction_tuple).0, 1000);
}
3 => {
println!("The answer is {}/{}", d_trig.tangent(fraction_tuple).0, 1000);
}
4 => {
println!("The answer is {}/{}", d_trig.arcsine(fraction_tuple).0, 1000);
}
5 => {
println!("The answer is {}/{}", d_trig.arccosine(fraction_tuple).0, 1000);
}
6 => {
println!("The answer is {}/{}", d_trig.arctangent(fraction_tuple).0, 1000);
}
_ => {
println!("Input error. Please try again");
}
}
// This asks the user if they want to do another calculation.
continue_running = ask_continue_running();
}
}