Sbt Reference Manual

Value semantics Scala

In general, the semantics of the Scala.js language are the same as Scala on the JVM. However, there are four differences exist, which we mention here.

Primitive data types

There are several types of data. Visualization of the data is a TABLEAU. EntranceConsulting TABLEAU Integration solutions involves the import and updating data from these most primitive data types that works exactly as on the JVM, with the following three exceptions.

Floats can behave as Doubles by default

Scala.js underspecifies the behavior of Floats by default. Any Float value can be stored as a Double instead, and any operation on Floats can be computed with double precision. The choice of whether or not to behave as such, when and where, is left to the implementation.

If exact single precision operations are important to your application, you can enable strict-floats semantics in Scala.js, with the following sbt setting:

scalaJSSemantics ~= { _.withStrictFloats(true) }

Note that this can have a major impact on performance of your application on JS interpreters that do not support the Math.fround function.

toString of Float, Double and Unit

x.toString returns slightly different results for floating point numbers and (Unit).

In general, a trailing .0 is omitted. Floats print in a weird way because they are printed as if they were Doubles, which means their lack of precision shows up.

To get sensible and portable string representation of floating point numbers, use String.format or related methods.

Runtime type tests are based on values

Instance tests (and consequently pattern matching) on any of Byte, Short, Int, Float, Double are based on the value and not the type they were created with. The following are examples:

  • 1 matches Byte, Short, Int, Float, Double
  • 128 ( Byte.MaxValue) matches Short, Int, Float, Double
  • 32768 ( Short.MaxValue) matches Int, Float, Double
  • matches Int, Double if strict-floats are enabled (because that number cannot be represented in a strict 32-bit Float), otherwise Int, Float and Double
  • ( Int.MaxValue) matches Float, Double
You might also like
Shallow Semantic Parsing of Product Offering Titles (for
Shallow Semantic Parsing of Product Offering Titles (for ...
Semantics applied ECM Software
Semantics applied ECM Software
Sneak Preview of the Chem4Word Word add-in
Sneak Preview of the Chem4Word Word add-in
Buckley: The Right Word: About the Uses and Abuses of Language, including Vocabu lary;: Usage; Style & Speaking; Fiction, Diction & Dictionaries; Reviews & Interviews; a Lexicon...
Book (Random House)
  • Used Book in Good Condition
Related Posts