Skip to content

Commit 16d9a1a

Browse files
committed
switch to floor
1 parent 4ca6a7e commit 16d9a1a

1 file changed

Lines changed: 2 additions & 16 deletions

File tree

js/closure/openlocationcode.js

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -384,14 +384,14 @@ exports.encode = encode;
384384
* @return {Array<number>} A tuple of the latitude integer and longitude integer.
385385
*/
386386
function _locationToIntegers(latitude, longitude) {
387-
var latVal = roundAwayFromZero(latitude * FINAL_LAT_PRECISION);
387+
var latVal = Math.floor(latitude * FINAL_LAT_PRECISION);
388388
latVal += LATITUDE_MAX * FINAL_LAT_PRECISION;
389389
if (latVal < 0) {
390390
latVal = 0;
391391
} else if (latVal >= 2 * LATITUDE_MAX * FINAL_LAT_PRECISION) {
392392
latVal = 2 * LATITUDE_MAX * FINAL_LAT_PRECISION - 1;
393393
}
394-
var lngVal = roundAwayFromZero(longitude * FINAL_LNG_PRECISION);
394+
var lngVal = Math.floor(longitude * FINAL_LNG_PRECISION);
395395
lngVal += LONGITUDE_MAX * FINAL_LNG_PRECISION;
396396
if (lngVal < 0) {
397397
lngVal =
@@ -694,20 +694,6 @@ function shorten(code, latitude, longitude) {
694694
}
695695
exports.shorten = shorten;
696696

697-
/**
698-
* Round numbers like C does. This implements rounding away from zero (see
699-
* https://en.wikipedia.org/wiki/Rounding).
700-
*
701-
* @param {number} num A number to round.
702-
* @return {number} The rounded value usn
703-
*/
704-
function roundAwayFromZero(num) {
705-
if (num >= 0) {
706-
return Math.round(num);
707-
}
708-
return -1 * Math.round(Math.abs(num));
709-
}
710-
711697
/**
712698
Clip a latitude into the range -90 to 90.
713699
@param {number} latitude A latitude in signed decimal degrees.

0 commit comments

Comments
 (0)