minor cleanup
This commit is contained in:
parent
351d845992
commit
f7d6ee9d7e
2 changed files with 13 additions and 9 deletions
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "quickmaths"
|
name = "quickmaths"
|
||||||
version = "0.2.2"
|
version = "0.2.3"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
@ -15,5 +15,5 @@ codegen-units = 1
|
||||||
debug = false
|
debug = false
|
||||||
lto = true
|
lto = true
|
||||||
panic = "abort"
|
panic = "abort"
|
||||||
strip = "debuginfo"
|
strip = "symbols"
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,11 @@ use evalexpr::{
|
||||||
|
|
||||||
use crate::util;
|
use crate::util;
|
||||||
|
|
||||||
|
pub type EvalResult = Result<Value, EvalexprError>;
|
||||||
|
|
||||||
|
|
||||||
// Mathematics
|
// Mathematics
|
||||||
pub fn fix(arg: &Value) -> Result<Value, EvalexprError> {
|
pub fn fix(arg: &Value) -> EvalResult {
|
||||||
let args = arg.as_tuple()?;
|
let args = arg.as_tuple()?;
|
||||||
|
|
||||||
let count = args.len();
|
let count = args.len();
|
||||||
|
@ -23,7 +26,7 @@ pub fn fix(arg: &Value) -> Result<Value, EvalexprError> {
|
||||||
return Ok(output.into());
|
return Ok(output.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn logarithm(arg: &Value) -> Result<Value, EvalexprError> {
|
pub fn logarithm(arg: &Value) -> EvalResult {
|
||||||
let arguments: Vec<Value>;
|
let arguments: Vec<Value>;
|
||||||
let count: usize;
|
let count: usize;
|
||||||
if arg.is_tuple() {
|
if arg.is_tuple() {
|
||||||
|
@ -66,7 +69,7 @@ pub fn logarithm(arg: &Value) -> Result<Value, EvalexprError> {
|
||||||
return Ok(output);
|
return Ok(output);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn square_root(arg: &Value) -> Result<Value, EvalexprError> {
|
pub fn square_root(arg: &Value) -> EvalResult {
|
||||||
if !arg.is_number() {
|
if !arg.is_number() {
|
||||||
return Err(EvalexprError::CustomMessage("Expected a number.".to_string()));
|
return Err(EvalexprError::CustomMessage("Expected a number.".to_string()));
|
||||||
}
|
}
|
||||||
|
@ -74,8 +77,9 @@ pub fn square_root(arg: &Value) -> Result<Value, EvalexprError> {
|
||||||
return Ok(value.sqrt().into());
|
return Ok(value.sqrt().into());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Data Science
|
// Data Science
|
||||||
pub fn average(arg: &Value) -> Result<Value, EvalexprError> {
|
pub fn average(arg: &Value) -> EvalResult {
|
||||||
let arguments = arg.as_tuple()?;
|
let arguments = arg.as_tuple()?;
|
||||||
let count = arguments.len() as i64;
|
let count = arguments.len() as i64;
|
||||||
let mut is_float = false;
|
let mut is_float = false;
|
||||||
|
@ -115,7 +119,7 @@ pub fn average(arg: &Value) -> Result<Value, EvalexprError> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Radix conversion
|
// Radix conversion
|
||||||
pub fn binary(arg: &Value) -> Result<Value, EvalexprError> {
|
pub fn binary(arg: &Value) -> EvalResult {
|
||||||
if !arg.is_string() {
|
if !arg.is_string() {
|
||||||
let num = arg.as_int()?;
|
let num = arg.as_int()?;
|
||||||
let fmt = format!("0b{:b}", num);
|
let fmt = format!("0b{:b}", num);
|
||||||
|
@ -124,7 +128,7 @@ pub fn binary(arg: &Value) -> Result<Value, EvalexprError> {
|
||||||
util::parse_radix("0b", 2, arg)
|
util::parse_radix("0b", 2, arg)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn hexadecimal(arg: &Value) -> Result<Value, EvalexprError> {
|
pub fn hexadecimal(arg: &Value) -> EvalResult {
|
||||||
if !arg.is_string() {
|
if !arg.is_string() {
|
||||||
let num = arg.as_int()?;
|
let num = arg.as_int()?;
|
||||||
let fmt = format!("0x{:X}", num);
|
let fmt = format!("0x{:X}", num);
|
||||||
|
@ -133,7 +137,7 @@ pub fn hexadecimal(arg: &Value) -> Result<Value, EvalexprError> {
|
||||||
util::parse_radix("0x", 16, arg)
|
util::parse_radix("0x", 16, arg)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn octal(arg: &Value) -> Result<Value, EvalexprError> {
|
pub fn octal(arg: &Value) -> EvalResult {
|
||||||
if !arg.is_string() {
|
if !arg.is_string() {
|
||||||
let num = arg.as_int()?;
|
let num = arg.as_int()?;
|
||||||
let fmt = format!("{:#o}", num);
|
let fmt = format!("{:#o}", num);
|
||||||
|
|
Loading…
Reference in a new issue