Skip to content

Commit c0958a8

Browse files
committed
fix a bug in complex power
1 parent 4136eb4 commit c0958a8

File tree

4 files changed

+9
-15
lines changed

4 files changed

+9
-15
lines changed

src/algorithm/monadic.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -912,8 +912,8 @@ impl Value {
912912
/// Decode the `bits` of the value
913913
pub fn unbits(&self, env: &Uiua) -> UiuaResult<Value> {
914914
match self {
915-
Value::Byte(n) => n.inverse_bits(env),
916-
Value::Num(n) => n.inverse_bits(env),
915+
Value::Byte(n) => n.un_bits(env),
916+
Value::Num(n) => n.un_bits(env),
917917
_ => Err(env.error("Argument to inverse_bits must be an array of integers")),
918918
}
919919
}
@@ -997,7 +997,7 @@ where
997997
Array<T>: Into<Value>,
998998
{
999999
/// Decode the `bits` of the array
1000-
pub fn inverse_bits(&self, env: &Uiua) -> UiuaResult<Value> {
1000+
pub fn un_bits(&self, env: &Uiua) -> UiuaResult<Value> {
10011001
for &n in &self.data {
10021002
if !n.is_int() {
10031003
return Err(env.error(format!(

src/complex.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,7 @@ impl Complex {
110110
pub fn powc(self, power: impl Into<Self>) -> Self {
111111
let power = power.into();
112112
if power.im == 0.0 {
113-
if self.im == 0.0 {
114-
return if self.re >= 0.0 {
115-
Self::new(self.re.powf(power.re), 0.0)
116-
} else {
117-
Self::new(0.0, self.re.abs().powf(power.re))
118-
};
119-
}
120-
if power.re == 0.0 {
121-
return Self::ONE;
122-
}
113+
return self.powf(power.re);
123114
}
124115
let (r, theta) = self.to_polar();
125116
((r.ln() + Self::I * theta) * power).exp()
@@ -129,8 +120,8 @@ impl Complex {
129120
if power == 0.0 {
130121
return Self::ONE;
131122
}
132-
if power.fract() == 0.0 {
133-
return Self::new(self.re.powf(power), self.im.powf(power));
123+
if power.fract() == 0.0 && self.im == 0.0 {
124+
return self.re.powf(power).into();
134125
}
135126
let (r, theta) = self.to_polar();
136127
Self::from_polar(r.powf(power), theta * power)

src/value.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@ impl Value {
389389
pub fn undo_fix(&mut self) {
390390
unsafe { self.repr_mut() }.arr.undo_fix();
391391
}
392+
#[track_caller]
392393
pub(crate) fn validate_shape(&self) {
393394
let repr = unsafe { self.repr() };
394395
validate_shape(&repr.arr.shape, repr.arr.data.len());

todo.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Uiua Todo
22

33
- 0.12
4+
- Optimize `indexof` allocation
5+
- Stack visualization output comments
46
- Stack-source locality tutorial
57
- Axis swizzles?
68
- Rewrite .uasm format

0 commit comments

Comments
 (0)