abs.js (1925B)
1 /** 2 * @license Apache-2.0 3 * 4 * Copyright (c) 2020 The Stdlib Authors. 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 'use strict'; 20 21 // MODULES // 22 23 var dispatch = require( './../../../tools/unary' ); 24 var config = require( './config.json' ); 25 var table = require( './table.js' ); 26 27 28 // MAIN // 29 30 /** 31 * Computes the absolute value. 32 * 33 * @name abs 34 * @type {Function} 35 * @param {(ndarray|Collection|number)} x - input value 36 * @param {Options} [options] - options 37 * @param {string} [options.order] - output array order 38 * @param {string} [options.dtype] - output array dtype 39 * @throws {TypeError} first argument must be a supported data type 40 * @throws {TypeError} options argument must be an object 41 * @throws {TypeError} must provide valid options 42 * @returns {(ndarray|Collection|number)} results 43 * 44 * @example 45 * var y = abs( -1.0 ); 46 * // returns 1.0 47 * 48 * @example 49 * var Float64Array = require( '@stdlib/array/float64' ); 50 * 51 * var x = new Float64Array( [ 1.0, -1.0, 0.0 ] ); 52 * 53 * var y = abs( x ); 54 * // returns <Float64Array>[ 1.0, 1.0, 0.0 ] 55 * 56 * @example 57 * var x = [ 1.0, -1.0, 0.0 ]; 58 * 59 * var y = abs( x ); 60 * // returns [ 1.0, 1.0, 0.0 ] 61 * 62 * @example 63 * var array = require( '@stdlib/ndarray/array' ); 64 * 65 * var x = array( [ [ 1.0, -2.0 ], [ -3.0, 4.0 ] ] ); 66 * // returns <ndarray> 67 * 68 * var y = abs( x ); 69 * // returns <ndarray> 70 * 71 * var v = y.get( 0, 1 ); 72 * // 2.0 73 */ 74 var abs = dispatch( table, config ); 75 76 77 // EXPORTS // 78 79 module.exports = abs;