[READ-ONLY] Mirror of https://github.com/probablykasper/cpc. Text calculator with support for units and conversion cpc.kasper.space
calculator cli conversion converter library math package units units-converter wasm website
0

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #3 from joseluis/master

fix spelling: Celcius → Celsius

authored by

Kasper and committed by
GitHub
(Jan 14, 2021, 5:34 PM +0100) c5afa7e0 249e44d8

+15 -15
+1 -1
README.md
··· 43 43 use cpc::{eval}; 44 44 use cpc::units::Unit; 45 45 46 - match eval("3m + 1cm", true, Unit::Celcius, false) { 46 + match eval("3m + 1cm", true, Unit::Celsius, false) { 47 47 Ok(answer) => { 48 48 // answer: Number { value: 301, unit: Unit::Centimeter } 49 49 println!("Evaluated value: {} {:?}", answer.value, answer.unit)
+1 -1
src/lexer.rs
··· 385 385 "kn" | "kt" | "knot" | "knots" => tokens.push(Token::Unit(Knot)), 386 386 387 387 "k" | "kelvin" | "kelvins" => tokens.push(Token::Unit(Kelvin)), 388 - "c" | "celcius" => tokens.push(Token::Unit(Celcius)), 388 + "c" | "celsius" => tokens.push(Token::Unit(Celsius)), 389 389 "f" | "fahrenheit" | "fahrenheits" => tokens.push(Token::Unit(Fahrenheit)), 390 390 "deg" | "degree" | "degrees" => tokens.push(Token::Unit(default_degree)), 391 391
+2 -2
src/lib.rs
··· 11 11 //! use cpc::{eval}; 12 12 //! use cpc::units::Unit; 13 13 //! 14 - //! match eval("3m + 1cm", true, Unit::Celcius, false) { 14 + //! match eval("3m + 1cm", true, Unit::Celsius, false) { 15 15 //! Ok(answer) => { 16 16 //! // answer: Number { value: 301, unit: Unit::Centimeter } 17 17 //! println!("Evaluated value: {} {:?}", answer.value, answer.unit) ··· 201 201 /// use cpc::{eval}; 202 202 /// use cpc::units::Unit; 203 203 /// 204 - /// match eval("3m + 1cm", true, Unit::Celcius, false) { 204 + /// match eval("3m + 1cm", true, Unit::Celsius, false) { 205 205 /// Ok(answer) => { 206 206 /// // answer: Number { value: 301, unit: Unit::Centimeter } 207 207 /// println!("Evaluated value: {} {:?}", answer.value, answer.unit)
+1 -1
src/main.rs
··· 10 10 debug = true; 11 11 } 12 12 if args.len() >= 2 { 13 - match eval(&args[1], true, Unit::Celcius, debug) { 13 + match eval(&args[1], true, Unit::Celsius, debug) { 14 14 Ok(answer) => { 15 15 if !debug { 16 16 println!("{} {:?}", answer.value, answer.unit)
+10 -10
src/units.rs
··· 258 258 Knot: (Speed, d128!(1.852)), 259 259 260 260 Kelvin: (Temperature, d128!(0)), 261 - Celcius: (Temperature, d128!(0)), 261 + Celsius: (Temperature, d128!(0)), 262 262 Fahrenheit: (Temperature, d128!(0)), 263 263 ); 264 264 ··· 303 303 if number.unit.category() == UnitType::Temperature { 304 304 match (number.unit, to_unit) { 305 305 (Kelvin, Kelvin) => ok(value), 306 - (Kelvin, Celcius) => ok(value-d128!(273.15)), 306 + (Kelvin, Celsius) => ok(value-d128!(273.15)), 307 307 (Kelvin, Fahrenheit) => ok(value*d128!(1.8)-d128!(459.67)), 308 - (Celcius, Celcius) => ok(value), 309 - (Celcius, Kelvin) => ok(value+d128!(273.15)), 310 - (Celcius, Fahrenheit) => ok(value*d128!(1.8)+d128!(32)), 308 + (Celsius, Celsius) => ok(value), 309 + (Celsius, Kelvin) => ok(value+d128!(273.15)), 310 + (Celsius, Fahrenheit) => ok(value*d128!(1.8)+d128!(32)), 311 311 (Fahrenheit, Fahrenheit) => ok(value), 312 312 (Fahrenheit, Kelvin) => ok((value+d128!(459.67))*d128!(5)/d128!(9)), 313 - (Fahrenheit, Celcius) => ok((value-d128!(32))/d128!(1.8)), 313 + (Fahrenheit, Celsius) => ok((value-d128!(32))/d128!(1.8)), 314 314 _ => Err(format!("Error converting temperature {:?} to {:?}", number.unit, to_unit)), 315 315 } 316 316 } else { ··· 865 865 assert_eq!(convert_test(1.609344, KilometersPerHour, MilesPerHour), 1.0); 866 866 assert_eq!(convert_test(1.852, KilometersPerHour, Knot), 1.0); 867 867 868 - assert_eq!(convert_test(274.15, Kelvin, Celcius), 1.0); 868 + assert_eq!(convert_test(274.15, Kelvin, Celsius), 1.0); 869 869 assert_eq!(convert_test(300.0, Kelvin, Fahrenheit), 80.33); 870 - assert_eq!(convert_test(-272.15, Celcius, Kelvin), 1.0); 871 - assert_eq!(convert_test(-15.0, Celcius, Fahrenheit), 5.0); 870 + assert_eq!(convert_test(-272.15, Celsius, Kelvin), 1.0); 871 + assert_eq!(convert_test(-15.0, Celsius, Fahrenheit), 5.0); 872 872 assert_eq!(convert_test(80.33, Fahrenheit, Kelvin), 300.0); 873 - assert_eq!(convert_test(5.0, Fahrenheit, Celcius), -15.0); 873 + assert_eq!(convert_test(5.0, Fahrenheit, Celsius), -15.0); 874 874 } 875 875 }