Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions core/src/avm2/globals/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::avm2::object::Object;
use crate::avm2::parameters::ParametersExt;
use crate::avm2::value::Value;
use crate::avm2::{ClassObject, Error};
use num_traits::ToPrimitive;
use rand::Rng;

macro_rules! wrap_std {
Expand Down Expand Up @@ -123,6 +124,30 @@ pub fn pow<'gc>(
let n = args.get_f64(0);
let p = args.get_f64(1);

// This condition is the simplest one that covers all special cases,
// so use it in order to create a fast path for finite n and p, which is
// the most common configuration.
if !n.is_finite() || !p.is_finite() {
match (n, p) {
// Special case: If p is NaN, the result is NaN.
(_, _) if p.is_nan() => return Ok(f64::NAN.into()),
// Special case: If p is ±Infinity and n is ±1, the result is NaN.
(1.0, _) | (-1.0, _) => {
// If (1) n or p is not finite, (2) p is not NaN, (3) n is finite,
// p has to be infinite.
debug_assert!(p.is_infinite());
return Ok(f64::NAN.into());
}
// Special case: If n is -Infinity and p < 0 and p is a negative even integer, Flash Player returns -0.
(f64::NEG_INFINITY, _) if p.to_i64().is_some_and(|i| i % 2 == 0 && i < 0) => {
return Ok(Value::Number(-0.0))
}
_ => {
// Fall back to regular powf
}
}
}

Ok(f64::powf(n, p).into())
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
num_ticks = 1
known_failure = true
Loading