C++: Round towards positive infinity (#1134)

This commit is contained in:
Guillaume Jenkins 2018-08-28 10:59:21 -04:00 committed by GitHub
parent 03ba8141ab
commit 239952aff5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -772,7 +772,9 @@ TNumber trunc(TNumber x){SINGLE(trunc)}
//%
TNumber round(TNumber x) {
SINGLE(round)
// In C++, round(-1.5) == -2, while in JS, round(-1.5) == -1. Align to the JS convention for consistency between
// simulator and device. The following does rounding with ties (x.5) going towards positive infinity.
return fromDouble(::floor(toDouble(x) + 0.5));
}
//%