Stream: contributing

Topic: Num.pow can return NaN


view this post on Zulip Kevin Gillette (Apr 15 2022 at 03:11):

Num.sqrt is planned to panic on negative values, yet Num.pow n 0.5 is equivalently a square root operation and returns NaN on negative values.

» Num.pow -1 0.5

NaN : Float *

Should we plan to make pow panic on roots of negative values, and add a corresponding Num.powChecked?

view this post on Zulip Richard Feldman (Apr 15 2022 at 14:40):

great catch!

view this post on Zulip Richard Feldman (Apr 15 2022 at 14:41):

I actually think we should leave this alone for now - once abilities have fully landed, and in particular once we disallow equality for floats (based on previous discussions) we'll presumably want to end up with both pow and sqrt being allowed to return NaN

view this post on Zulip Richard Feldman (Apr 15 2022 at 14:41):

I think it's okay if they're inconsistent in the meantime :big_smile:

view this post on Zulip Kevin Gillette (Apr 16 2022 at 01:39):

What is the general intent? Are abilities providing a great way to express checked vs panicking vs nan'ing variants of an operation, or are abilities just changing enough lines of code everywhere that we don't want the abilities work to deal with too many merge conflicts?

view this post on Zulip Ayaz Hafiz (Apr 16 2022 at 04:42):

More of the former, abilities will just allow us to express in Roc code things we can't readily do today


Last updated: Jul 06 2025 at 12:14 UTC