Skip to content

Known cross-platform limitations: Float fidelity on Scala.js, HashSet[Int] on Scala Native #23

Description

@halotukozak

Discovered while enabling real (not just compile-only) test execution on Scala.js and Scala Native. These are runtime/javalib limitations of the respective platforms, not bugs in mcodec's own code — documented here and scoped out via `//> using target.platform` on the affected tests so the rest of the suite still runs cross-platform.

Scala.js: Float loses precision and sign-bit fidelity

Scala.js represents Float as a JS Double under the hood (no native 32-bit float type). Two consequences observed in IoContractExtTest (now split into IoContractExtJvmOnlyTest.scala, JVM-only):

  • 1.1f round-tripped through JSON can drift to 1.100000023841858 (the classic float→double widening artifact) instead of staying 1.1.
  • -0.0f loses its sign bit through the write/read round-trip (Float.floatToIntBits differs from the JVM).

Scala Native: java.util.HashSet[Int] round-trip crashes

ExtendedStdCodecsTest's java.util.HashSet round-trips test (now JavaHashSetIntTest.scala, jvm+scala-js only) crashes with scala.scalanative.runtime.UndefinedBehaviorError: null on Scala Native 0.5.12. Passes fine on JVM and Scala.js. Looks like a scala-native javalib limitation around boxed Integer handling in HashSet, not something in mcodec's own code — not yet root-caused further.

Follow-up ideas

  • Revisit if/when scala-native or Scala.js address these upstream.
  • If real users hit the Float drift in practice on Scala.js, consider a from-scratch Float→string formatter instead of relying on the platform's Float#toString.

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