sp-math
v1.0.5
Published
Common Math Functions
Downloads
2
Readme
sp-math
Common Math Functions
Install
npm i sp-math //or yarn add sp-math
CDN
<script src="https://unpkg.com/sp-math/dist/index.min.js"></script>
<script>
</script>
Usage
const {
abs,
acos,
asin,
atan,
ceil,
degreeToRotate,
devideFloat,
isFloat,
rotateToDegree,
cos,
distance,
floor,
comma,
rotateByDegree,
pow,
round,
sin,
sqrt,
tan
} = require("sp-math")
abs(val)
- {Number} val
abs(-10); // return 10
ceil(val)
- {Number} val
ceil(1.25); // return 2
cos(val)
- {Number} val
cos(60); // return 0.5000000000000001
sin(val)
- {Number} val
sin(30); // return 0.49999999999999994
tan(val)
- {Number} val
sin(45); // return 0.9999999999999999
acos(val)
- {Number} val
acos(0.5); // return 60.00000000000001
asin(val)
- {Number} val
asin(0.5); // return 30.000000000000004
atan(val)
- {Number} val
atan(1); // return 45
degreeToRotate(val)
- {Number} val
degreeToRotate(180); // return 3.141592653589793 Math.PI
rotateToDegree(val)
- {Number} val
rotateToDegree(Math.PI); // return 180
distance(p1, p2)
- {Array} p1 = [0, 0]
- {Array} p2 = [0, 0]
distance([1, 1], [2, 2]); // return 1.41
floor(val)
- {Number} val
floor(1.25); // return 1
pow(x, y, isDeep = false)
- {Number} x
- {Number} y
- {Boolean} isDeep
pow(2, 5); // return 32 pow(-2, 5); // return -32 pow(4, 0.5, true); // return [2, -2]
round(val)
- {Number} val
round(2.53) // return 3 round(2.15); // return 2
sqrt(val)
- {Number} val
- {Boolean} isDeep
sqrt(4) // return 2 sqrt(4, true); // return [2, -2]
devideFloat(val)
- {Number} val
devideFloat(4) // return [ 4, 1 ] 4/1 = 4 devideFloat(1.8); // return [ 9, 5 ] 9/5 = 1.8
comma(val, obj = {fixed:2, hasComma = false})
- {Number} val
- {Object} obj
- {Number} obj.fixed
- {Boolean} obj.hasComma
comma('12345.33',{ fixed: 3 }); // return '12345.330' comma('12345.33',{ fixed: 3, hasComma: true }); // return '12,345.330' comma('12,345.330',{ fixed: 4, hasComma: false }); // return '12345.3300'