From 21d0cc814ed090f9619ff1851970ece48a350f5d Mon Sep 17 00:00:00 2001 From: royels Date: Fri, 20 May 2016 12:48:23 -0400 Subject: [PATCH] Changed the exponent function for rounding --- lib/functions/acos.js | 10 ++++++---- lib/functions/asin.js | 7 +++++-- lib/functions/atan.js | 7 +++++-- lib/functions/convert-angle.js | 10 ++++++++++ test/cases/bifs.math.css | 6 ++++++ test/cases/bifs.math.styl | 6 ++++++ 6 files changed, 38 insertions(+), 8 deletions(-) diff --git a/lib/functions/acos.js b/lib/functions/acos.js index c0bf0dd10..f4479db97 100644 --- a/lib/functions/acos.js +++ b/lib/functions/acos.js @@ -4,15 +4,17 @@ var utils = require('../utils') , asin = require('./asin'); /** - * Return the tangent of the given `angle`. + * Return the arccosine of the given `value`. * - * @param {Unit} angle + * @param {Double} trigValue + * @param {Unit} output * @return {Unit} * @api public */ - module.exports = function acos(trigValue, output) { var output = typeof output !== 'undefined' ? output : 'deg'; - var convertedValue = convert(Math.PI / 2, output) - asin(trigValue, output); + var convertedValue = convert(Math.PI / 2, output) - asin(trigValue, output).val; + var m = Math.pow(10, 9); + convertedValue = Math.round(convertedValue * m) / m; return new nodes.Unit(convertedValue, output); }; diff --git a/lib/functions/asin.js b/lib/functions/asin.js index 9db6f9237..5cfbcff78 100644 --- a/lib/functions/asin.js +++ b/lib/functions/asin.js @@ -3,16 +3,19 @@ var utils = require('../utils') , convert = require('./convert-angle'); /** - * Return the tangent of the given `angle`. + * Return the arcsine of the given `value`. * - * @param {Unit} angle + * @param {Double} trigValue + * @param {Unit} output * @return {Unit} * @api public */ module.exports = function atan(trigValue, output) { var output = typeof output !== 'undefined' ? output : 'deg'; + var m = Math.pow(10, 9); var value = Math.asin(trigValue) ; var convertedValue = convert(value, output); + convertedValue = Math.round(convertedValue * m) / m; return new nodes.Unit(convertedValue, output); }; diff --git a/lib/functions/atan.js b/lib/functions/atan.js index 932006975..90501650d 100644 --- a/lib/functions/atan.js +++ b/lib/functions/atan.js @@ -3,9 +3,10 @@ var utils = require('../utils') , convert = require('./convert-angle'); /** - * Return the tangent of the given `angle`. + * Return the arctangent of the given `value`. * - * @param {Unit} angle + * @param {Double} trigValue + * @param {Unit} output * @return {Unit} * @api public */ @@ -13,6 +14,8 @@ var utils = require('../utils') module.exports = function atan(trigValue, output) { var output = typeof output !== 'undefined' ? output : 'deg'; var value = Math.atan(trigValue) ; + var m = Math.pow(10, 9); var convertedValue = convert(value, output); + convertedValue = Math.round(convertedValue * m) / m; return new nodes.Unit(convertedValue, output); }; diff --git a/lib/functions/convert-angle.js b/lib/functions/convert-angle.js index 2f73e3fb5..d0832f26e 100644 --- a/lib/functions/convert-angle.js +++ b/lib/functions/convert-angle.js @@ -1,3 +1,13 @@ + +/** + * Convert given value's base into the parameter unitName + * + * @param {Double} value + * @param {String} unitName + * @return {Double} + * @api private + */ + module.exports = function convertAngle(value, unitName) { var factors = { "rad" : 1, diff --git a/test/cases/bifs.math.css b/test/cases/bifs.math.css index e12723738..d56444912 100644 --- a/test/cases/bifs.math.css +++ b/test/cases/bifs.math.css @@ -70,3 +70,9 @@ .math_atan { test1: 45deg; } +.math_asin { + test1: 44.999999985deg; +} +.math_acos { + test1: 45.000000015deg; +} diff --git a/test/cases/bifs.math.styl b/test/cases/bifs.math.styl index c04e5e23c..aaba9310f 100644 --- a/test/cases/bifs.math.styl +++ b/test/cases/bifs.math.styl @@ -65,3 +65,9 @@ .math_atan test1: atan(tan(45deg)) + +.math_asin + test1: asin(sin(45deg)) + +.math_acos + test1: acos(cos(45deg))