mirror of
https://github.com/PaddiM8/kalker.git
synced 2025-02-12 06:29:17 +01:00
Keep previous variable value after integration using the same identifier
This commit is contained in:
parent
c4c768374f
commit
f944e3cebc
@ -79,6 +79,9 @@ fn simpsons_rule(
|
|||||||
integration_variable: &str,
|
integration_variable: &str,
|
||||||
) -> Result<KalkNum, CalcError> {
|
) -> Result<KalkNum, CalcError> {
|
||||||
let mut result = KalkNum::default();
|
let mut result = KalkNum::default();
|
||||||
|
let original_variable_value = context
|
||||||
|
.symbol_table
|
||||||
|
.get_and_remove_var(integration_variable);
|
||||||
|
|
||||||
const N: i32 = 900;
|
const N: i32 = 900;
|
||||||
let a = interpreter::eval_expr(context, a_expr, "")?;
|
let a = interpreter::eval_expr(context, a_expr, "")?;
|
||||||
@ -105,6 +108,14 @@ fn simpsons_rule(
|
|||||||
result.imaginary_value += mul.imaginary_value;
|
result.imaginary_value += mul.imaginary_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(value) = original_variable_value {
|
||||||
|
context.symbol_table.insert(value);
|
||||||
|
} else {
|
||||||
|
context
|
||||||
|
.symbol_table
|
||||||
|
.get_and_remove_var(integration_variable);
|
||||||
|
}
|
||||||
|
|
||||||
Ok(result.mul_without_unit(KalkNum::new_with_imaginary(
|
Ok(result.mul_without_unit(KalkNum::new_with_imaginary(
|
||||||
3f64 / 8f64 * h.value,
|
3f64 / 8f64 * h.value,
|
||||||
&h.unit,
|
&h.unit,
|
||||||
|
@ -81,6 +81,10 @@ impl SymbolTable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_and_remove_var(&mut self, identifier: &str) -> Option<Stmt> {
|
||||||
|
self.hashmap.remove(&format!("var.{}", identifier))
|
||||||
|
}
|
||||||
|
|
||||||
pub fn contains_var(&self, identifier: &str) -> bool {
|
pub fn contains_var(&self, identifier: &str) -> bool {
|
||||||
prelude::CONSTANTS.contains_key(identifier)
|
prelude::CONSTANTS.contains_key(identifier)
|
||||||
|| identifier == "i"
|
|| identifier == "i"
|
||||||
|
Loading…
Reference in New Issue
Block a user