300826
This commit is contained in:
@@ -389,6 +389,26 @@ impl Engineering {
|
||||
self.sync_expr();
|
||||
}
|
||||
|
||||
/// Insert `× 10 ^` for scientific-notation entry: `1.5 [×10ˣ] 3 = 1500`.
|
||||
/// Exponent may be negated with ± before `=` (`10 ^ −3` parses correctly).
|
||||
pub fn mul_pow10(&mut self) {
|
||||
if self.error.is_some() {
|
||||
return;
|
||||
}
|
||||
if self.done {
|
||||
// Continue from the result: 1500 [×10ˣ] 2 = 150000.
|
||||
self.formula.clear();
|
||||
self.done = false;
|
||||
self.typing = true;
|
||||
}
|
||||
self.flush_entry();
|
||||
self.formula.push_str(" × 10 ^ ");
|
||||
self.entry = "0".into();
|
||||
self.typing = false;
|
||||
self.second = false;
|
||||
self.sync_expr();
|
||||
}
|
||||
|
||||
pub fn equals(&mut self) {
|
||||
if self.error.is_some() {
|
||||
return;
|
||||
@@ -884,6 +904,47 @@ mod tests {
|
||||
assert_eq!(e.display(), "1024");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mul_pow10_basic() {
|
||||
// 1.5 ×10ˣ 3 = 1500 (× 10 ^ с приоритетом ^ над ×).
|
||||
let mut e = Engineering::new();
|
||||
e.input_digit('1');
|
||||
e.input_dot();
|
||||
e.input_digit('5');
|
||||
e.mul_pow10();
|
||||
e.input_digit('3');
|
||||
e.equals();
|
||||
assert_eq!(e.display(), "1500");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mul_pow10_negative_exponent() {
|
||||
// 2.5 ×10ˣ ±2 = 0.025.
|
||||
let mut e = Engineering::new();
|
||||
e.input_digit('2');
|
||||
e.input_dot();
|
||||
e.input_digit('5');
|
||||
e.mul_pow10();
|
||||
e.input_digit('2');
|
||||
e.negate();
|
||||
e.equals();
|
||||
assert_eq!(e.display(), "0.025");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mul_pow10_continues_result() {
|
||||
// 2 × 3 = 6, затем 6 ×10ˣ 2 = 600.
|
||||
let mut e = Engineering::new();
|
||||
e.input_digit('2');
|
||||
e.set_op("×");
|
||||
e.input_digit('3');
|
||||
e.equals();
|
||||
e.mul_pow10();
|
||||
e.input_digit('2');
|
||||
e.equals();
|
||||
assert_eq!(e.display(), "600");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ten_pow_negative_not_zero() {
|
||||
// 10 ^ −50 ≈ 1e-50 was snapped to "0" by format_num.
|
||||
|
||||
@@ -532,6 +532,7 @@ fn handle_engineering(calc: &mut Engineering, id: &str) {
|
||||
"eng:fact" => calc.insert_func("fact"),
|
||||
"eng:exp" => calc.insert_func("exp"),
|
||||
"eng:tenpow" => calc.insert_func("tenpow"),
|
||||
"eng:mul10pow" => calc.mul_pow10(),
|
||||
"eng:log" => calc.insert_func("log"),
|
||||
"eng:ln" => calc.insert_func("ln"),
|
||||
"MC" => calc.memory_clear(),
|
||||
|
||||
Reference in New Issue
Block a user