Skip to content

Commit a412e9d

Browse files
committed
Add quirks doc
1 parent 70bcdb3 commit a412e9d

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

docs/javascript_quirks.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# JavaScript Quirks
2+
3+
> A list of JavaScript quirks which should be kept in mind when writing implementations.
4+
5+
## Rounding
6+
7+
1. The JavaScript standard ([ECMA-262][ecma-262-math-round]) defines the behavior of `Math.round` such that "ties" (e.g., `1.5` and `-1.5`) are rounded toward `+infinity`.
8+
9+
```javascript
10+
var x = Math.round( 1.5 );
11+
// returns 2.0
12+
13+
x = Math.round( -1.5 );
14+
// returns -1.0
15+
```
16+
17+
This behavior is relatively uncommon among languages implementing a round operation for floating-point numbers and appears to have originated by following [Java][java-math-round].
18+
19+
When implementing lower-level math functions which may require rounding, exercise caution when considering whether the built-in rounding behavior is appropriate and ensure that bias is not introduced in computed results.
20+
21+
22+
<section class="links">
23+
24+
[ecma-262-math-round]: http://www.ecma-international.org/ecma-262/6.0/#sec-math.round
25+
26+
[java-math-round]: https://docs.oracle.com/javase/7/docs/api/java/lang/Math.html#round%28double%29
27+
28+
</section>

0 commit comments

Comments
 (0)