[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.

Add Bps bytes per second units

Kasper (Jun 27, 2026, 5:10 AM +0200) 8438ad2f 6eda996b

+19 -5
+1
CHANGELOG.md
··· 6 6 - Add generic unit combinations, such as `1kg/m`, `1km per year` and `m+km` 7 7 - Add generic unit simplification. For example, `1kg*1sqm/1s/1s/1s/1a` now becomes `1 volt` 8 8 - Add `≈` indicator when a result is approximate 9 + - Add case-sensitive `Bps` units for bytes per second 9 10 - Use max precision for inexact unit conversions 10 11 - Fix `^` allowing numbers to be raised to the power of units 11 12
-2
README.md
··· 161 161 ``` 162 162 163 163 ### Potential Improvements 164 - - Support for conversion between Power, Current, Resistance and Voltage. Multiplication and division is currently supported, but not conversions using sqrt or pow. 165 164 - Fractional numbers (to make 1/3*2*3 accurate) 166 165 - E notation, like 2E+10 167 166 - Unit types ··· 172 171 - Timezones 173 172 - Binary/octal/decimal/hexadecimal/base32/base64 174 173 - Fuel consumption 175 - - Data transfer rate 176 174 - Color codes 177 175 - Force 178 176 - Roman numerals
+18 -3
src/lexer.rs
··· 98 98 Some(c) => *c, 99 99 None => return Ok(()), 100 100 }; 101 - let token = match first_grapheme { 101 + let token = match first_grapheme.to_ascii_lowercase().as_str() { 102 102 grapheme if grapheme.trim_start().is_empty() => { 103 103 lexer.graphemes.next(); 104 104 return Ok(()); ··· 163 163 } 164 164 165 165 fn lex_word(word: &str, lexer: &mut Lexer) -> Result<(), String> { 166 - let token = match word { 166 + let token = match word.to_ascii_lowercase().as_str() { 167 167 "to" => Token::TextOperator(To), 168 168 "of" => Token::TextOperator(Of), 169 169 ··· 451 451 "zib" | "zebibyte" | "zebibytes" => Token::unit(Zebibyte), 452 452 "yib" | "yobibyte" | "yobibytes" => Token::unit(Yobibyte), 453 453 454 + "bps" if word.as_bytes()[0] == b'B' => Token::unit(BytesPerSecond), 455 + "kbps" if word.as_bytes()[1] == b'B' => Token::unit(KilobytesPerSecond), 456 + "mbps" if word.as_bytes()[1] == b'B' => Token::unit(MegabytesPerSecond), 457 + "gbps" if word.as_bytes()[1] == b'B' => Token::unit(GigabytesPerSecond), 458 + "tbps" if word.as_bytes()[1] == b'B' => Token::unit(TerabytesPerSecond), 459 + "pbps" if word.as_bytes()[1] == b'B' => Token::unit(PetabytesPerSecond), 460 + "ebps" if word.as_bytes()[1] == b'B' => Token::unit(ExabytesPerSecond), 461 + "zbps" if word.as_bytes()[1] == b'B' => Token::unit(ZettabytesPerSecond), 462 + "ybps" if word.as_bytes()[1] == b'B' => Token::unit(YottabytesPerSecond), 463 + 454 464 "bps" => Token::unit(BitsPerSecond), 455 465 "kbps" => Token::unit(KilobitsPerSecond), 456 466 "mbps" => Token::unit(MegabitsPerSecond), ··· 655 665 656 666 /// Lex an input string and returns [`Token`]s 657 667 pub fn lex(input: &str, remove_trailing_operator: bool) -> Result<Vec<Token>, String> { 658 - let mut input = input.replace(',', "").to_ascii_lowercase(); 668 + let mut input = input.replace(',', ""); 659 669 660 670 if remove_trailing_operator { 661 671 match &input.chars().last().unwrap_or('x') { ··· 959 969 run_datarate_lex("0.73 exbibytes", vec![numtok!(0.73), Token::unit(Exbibyte)]); 960 970 run_datarate_lex("0.49 zebibytes", vec![numtok!(0.49), Token::unit(Zebibyte)]); 961 971 run_datarate_lex("0.23 yobibytes", vec![numtok!(0.23), Token::unit(Yobibyte)]); 972 + run_lex("432 Bps", vec![numtok!(432), Token::unit(BytesPerSecond)]); 973 + run_lex( 974 + "56 kBps", 975 + vec![numtok!(56), Token::unit(KilobytesPerSecond)], 976 + ); 962 977 run_lex("432 bps", vec![numtok!(432), Token::unit(BitsPerSecond)]); 963 978 run_lex("56 kbps", vec![numtok!(56), Token::unit(KilobitsPerSecond)]); 964 979 run_lex("12 mbps", vec![numtok!(12), Token::unit(MegabitsPerSecond)]);