Skip to content

(d: Double).isNan boxes #12062

@lrytz

Description

@lrytz

(d: Double).isNan is compiled as Predef.double2Double(d).isNan(), which boxes the number.

Using Predef.doubleWrapper(1.0).isNaN would be preferable because RichDouble is a value class. However, doubleWrapper is a lower priority implicit than double2Double because it's defined in Predef's parent LowPriorityImplicits.

Other methods are also affected, e.g., longValue and friends, and using isInfinite boxes, where isInfinity doesn't.

Ideas:

  • swap the priority of the two implicits; but it seems rather risky to fiddle with double2Double at this point
  • rewrite the known calls in the backend
  • rely on inlining (doesn't work currenlty, it the inliner only rewrites it to new Double.isNan(d). Also, requires to enable inlining from the jdk, which is not recommended.)
  • rely on the jvm's escape analysis

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions