Support conversions between radians and degrees
This commit is contained in:
		
							parent
							
								
									a691732a81
								
							
						
					
					
						commit
						2eed8fc323
					
				
					 1 changed files with 10 additions and 4 deletions
				
			
		| 
						 | 
					@ -103,6 +103,8 @@ impl Op {
 | 
				
			||||||
					Func::Square => args[0].eval().pow(&BigFloat::from_f64(2.0, PRECISION), PRECISION, RoundingMode::None, &mut CONST_CACHE.lock().unwrap()),
 | 
										Func::Square => args[0].eval().pow(&BigFloat::from_f64(2.0, PRECISION), PRECISION, RoundingMode::None, &mut CONST_CACHE.lock().unwrap()),
 | 
				
			||||||
					Func::SquareRoot => args[0].eval().sqrt(PRECISION, RoundingMode::None),
 | 
										Func::SquareRoot => args[0].eval().sqrt(PRECISION, RoundingMode::None),
 | 
				
			||||||
					Func::Abs => args[0].eval().abs(),
 | 
										Func::Abs => args[0].eval().abs(),
 | 
				
			||||||
 | 
										Func::Deg => args[0].eval().mul(&Const::Pi.get_val().div(&BigFloat::from_f64(180.0, PRECISION), PRECISION, RoundingMode::None), PRECISION, RoundingMode::None),
 | 
				
			||||||
 | 
										Func::Rad => args[0].eval().mul(&BigFloat::from_f64(180.0, PRECISION).div(&Const::Pi.get_val(), PRECISION, RoundingMode::None), PRECISION, RoundingMode::None),
 | 
				
			||||||
					_ => {
 | 
										_ => {
 | 
				
			||||||
						error!("Got 1 params for func {:?} which expects 2 (should not be possible)", self);
 | 
											error!("Got 1 params for func {:?} which expects 2 (should not be possible)", self);
 | 
				
			||||||
						astro_float::NAN
 | 
											astro_float::NAN
 | 
				
			||||||
| 
						 | 
					@ -182,6 +184,8 @@ enum Func {
 | 
				
			||||||
	Square,
 | 
						Square,
 | 
				
			||||||
	SquareRoot,
 | 
						SquareRoot,
 | 
				
			||||||
	Abs,
 | 
						Abs,
 | 
				
			||||||
 | 
						Deg,
 | 
				
			||||||
 | 
						Rad,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
impl Func {
 | 
					impl Func {
 | 
				
			||||||
| 
						 | 
					@ -200,6 +204,8 @@ impl Func {
 | 
				
			||||||
			(Func::Square, &["square", "squared"]),
 | 
								(Func::Square, &["square", "squared"]),
 | 
				
			||||||
			(Func::SquareRoot, &["sqrt", "squareroot", "√"]),
 | 
								(Func::SquareRoot, &["sqrt", "squareroot", "√"]),
 | 
				
			||||||
			(Func::Abs, &["abs", "absolute"]),
 | 
								(Func::Abs, &["abs", "absolute"]),
 | 
				
			||||||
 | 
								(Func::Deg, &["deg", "degrees", "deg2rad"]),
 | 
				
			||||||
 | 
								(Func::Rad, &["rad", "radians", "rad2deg"]),
 | 
				
			||||||
		]
 | 
							]
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -281,8 +287,8 @@ impl Lexer<'_> {
 | 
				
			||||||
						for (f, names) in Func::names() {
 | 
											for (f, names) in Func::names() {
 | 
				
			||||||
							for name in *names {
 | 
												for name in *names {
 | 
				
			||||||
								let n_len = name.chars().count();
 | 
													let n_len = name.chars().count();
 | 
				
			||||||
								if self.data_ptr.starts_with(name) && (len == n_len || !self.data_ptr.chars().nth(n_len).unwrap().is_alphabetic()) {
 | 
													if self.data_ptr.starts_with(name) && (len == n_len || !self.data_ptr.chars().nth(n_len).unwrap().is_alphanumeric()) {
 | 
				
			||||||
									self.next_by = name.chars().count();
 | 
														self.next_by = n_len;
 | 
				
			||||||
									return Ok(Token::Op(Op::Func(*f)));
 | 
														return Ok(Token::Op(Op::Func(*f)));
 | 
				
			||||||
								}
 | 
													}
 | 
				
			||||||
							}
 | 
												}
 | 
				
			||||||
| 
						 | 
					@ -290,8 +296,8 @@ impl Lexer<'_> {
 | 
				
			||||||
						for (f, names) in Const::names() {
 | 
											for (f, names) in Const::names() {
 | 
				
			||||||
							for name in *names {
 | 
												for name in *names {
 | 
				
			||||||
								let n_len = name.chars().count();
 | 
													let n_len = name.chars().count();
 | 
				
			||||||
								if self.data_ptr.starts_with(name) && (len == n_len || !self.data_ptr.chars().nth(n_len).unwrap().is_alphabetic()) {
 | 
													if self.data_ptr.starts_with(name) && (len == n_len || !self.data_ptr.chars().nth(n_len).unwrap().is_alphanumeric()) {
 | 
				
			||||||
									self.next_by = name.chars().count();
 | 
														self.next_by = n_len;
 | 
				
			||||||
									return Ok(Token::Atom(Atom::Const(*f)));
 | 
														return Ok(Token::Atom(Atom::Const(*f)));
 | 
				
			||||||
								}
 | 
													}
 | 
				
			||||||
							}
 | 
												}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue