Skip to content

Commit

Permalink
fix a bug in complex power
Browse files Browse the repository at this point in the history
  • Loading branch information
kaikalii committed Jun 8, 2024
1 parent 4136eb4 commit c0958a8
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 15 deletions.
6 changes: 3 additions & 3 deletions src/algorithm/monadic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -912,8 +912,8 @@ impl Value {
/// Decode the `bits` of the value
pub fn unbits(&self, env: &Uiua) -> UiuaResult<Value> {
match self {
Value::Byte(n) => n.inverse_bits(env),
Value::Num(n) => n.inverse_bits(env),
Value::Byte(n) => n.un_bits(env),
Value::Num(n) => n.un_bits(env),
_ => Err(env.error("Argument to inverse_bits must be an array of integers")),
}
}
Expand Down Expand Up @@ -997,7 +997,7 @@ where
Array<T>: Into<Value>,
{
/// Decode the `bits` of the array
pub fn inverse_bits(&self, env: &Uiua) -> UiuaResult<Value> {
pub fn un_bits(&self, env: &Uiua) -> UiuaResult<Value> {
for &n in &self.data {
if !n.is_int() {
return Err(env.error(format!(
Expand Down
15 changes: 3 additions & 12 deletions src/complex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,7 @@ impl Complex {
pub fn powc(self, power: impl Into<Self>) -> Self {
let power = power.into();
if power.im == 0.0 {
if self.im == 0.0 {
return if self.re >= 0.0 {
Self::new(self.re.powf(power.re), 0.0)
} else {
Self::new(0.0, self.re.abs().powf(power.re))
};
}
if power.re == 0.0 {
return Self::ONE;
}
return self.powf(power.re);
}
let (r, theta) = self.to_polar();
((r.ln() + Self::I * theta) * power).exp()
Expand All @@ -129,8 +120,8 @@ impl Complex {
if power == 0.0 {
return Self::ONE;
}
if power.fract() == 0.0 {
return Self::new(self.re.powf(power), self.im.powf(power));
if power.fract() == 0.0 && self.im == 0.0 {
return self.re.powf(power).into();
}
let (r, theta) = self.to_polar();
Self::from_polar(r.powf(power), theta * power)
Expand Down
1 change: 1 addition & 0 deletions src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ impl Value {
pub fn undo_fix(&mut self) {
unsafe { self.repr_mut() }.arr.undo_fix();
}
#[track_caller]
pub(crate) fn validate_shape(&self) {
let repr = unsafe { self.repr() };
validate_shape(&repr.arr.shape, repr.arr.data.len());
Expand Down
2 changes: 2 additions & 0 deletions todo.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Uiua Todo

- 0.12
- Optimize `indexof` allocation
- Stack visualization output comments
- Stack-source locality tutorial
- Axis swizzles?
- Rewrite .uasm format
Expand Down

0 comments on commit c0958a8

Please sign in to comment.