Skip to content

perf: use copysign over if y < 0.0 { -x } else { x } #70

Description

@michaelkirk

There are a few places in the codebase that do things like this.

-            t3 += if t3 < 0.0 { -disc.sqrt() } else { disc.sqrt() };
+            t3 += disc.sqrt().copysign(t3);

Searching for < 0.0 might lead you to some other examples.

It's a small thing but might help with branch prediction.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions