Math functions need some special cases #2

Open
opened 2022-11-17 05:37:39 +00:00 by auravulpes · 1 comment
Owner

What is pow(1, INFINITY)? What about sin(NAN)? log(-3)? Right now, my code takes any of those sorts of nonsensical queries and tries to legitimately calculate them, but it shouldn't. It needs special cases for that sort of stuff. I'll come in tomorrow and actually try to list out a bunch of them for the code I've already written.

What is pow(1, INFINITY)? What about sin(NAN)? log(-3)? Right now, my code takes any of those sorts of nonsensical queries and tries to legitimately calculate them, but it shouldn't. It needs special cases for that sort of stuff. I'll come in tomorrow and actually try to list out a bunch of them for the code I've already written.
auravulpes added the
bug
label 2022-11-17 05:37:39 +00:00
Author
Owner

Okay, so, according to IEEE 754-2019 and the C99 standard...

(nb: k is used for an arbitrary number, +k is arbitrary positive number, -k is an arbitrary negative number, v is an arbitrary even, d is an arbitrary odd, i is an arbitrary integer, r is an arbitrary non-integer, 0 can be either +0 or -0, and rules take priority from top to bottom)

pow():

  • k^0 = 1 (k not a signaling NaN; includes 0^0)
  • 0^-d = INF, divByZero
  • 0^-INF = +INF
  • 0^+INF = 0
  • 0^+k = 0 (matching sign)
  • -1^INF = 1
  • 1^k = 1
  • k^+INF = 0, |k| < 1
  • k^+INF = +INF, |k| > 1
  • k^-INF = +INF, |k| < 1
  • k^-INF = 0, |k| > 1
  • +INF^-k = 0
  • +INF^+k = +INF
  • -INF^-d = -0
  • -INF^+d = -INF
  • -INF^-v = +0
  • -INF^+v = +INF
  • 0^-v = +INF, divByZero
  • 0^+v = +0
  • -k^r => invalid operation/domain error

exp():

  • exp(+INF) = +INF
  • exp(-INF) = +0
  • Range error if input too large

log():

  • log(+INF) = +INF
  • log(0) = -INF, divByZero
  • log(1) = +0 (might be good to include)
  • log(-k) => domain error

sqrt():

  • sqrt(-k) => domain error

I'm not sure this covers everything, but it's definitely a nice start. I'll, like, see what musl does for some other cases (e.g. sin(NaN)) later.

Okay, so, according to IEEE 754-2019 and the C99 standard... (nb: k is used for an arbitrary number, +k is arbitrary positive number, -k is an arbitrary negative number, v is an arbitrary even, d is an arbitrary odd, i is an arbitrary integer, r is an arbitrary non-integer, 0 can be either +0 or -0, and rules take priority from top to bottom) pow(): * k^0 = 1 (k not a signaling NaN; includes 0^0) * 0^-d = INF, divByZero * 0^-INF = +INF * 0^+INF = 0 * 0^+k = 0 (matching sign) * -1^INF = 1 * 1^k = 1 * k^+INF = 0, |k| < 1 * k^+INF = +INF, |k| > 1 * k^-INF = +INF, |k| < 1 * k^-INF = 0, |k| > 1 * +INF^-k = 0 * +INF^+k = +INF * -INF^-d = -0 * -INF^+d = -INF * -INF^-v = +0 * -INF^+v = +INF * 0^-v = +INF, divByZero * 0^+v = +0 * -k^r => invalid operation/domain error exp(): * exp(+INF) = +INF * exp(-INF) = +0 * Range error if input too large log(): * log(+INF) = +INF * log(0) = -INF, divByZero * log(1) = +0 (might be good to include) * log(-k) => domain error sqrt(): * sqrt(-k) => domain error I'm not sure this covers everything, but it's definitely a nice start. I'll, like, see what musl does for some other cases (e.g. sin(NaN)) later.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: auravulpes/FENIX_libc#2
No description provided.