main.js (1276B)
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 float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); 24 25 26 // VARIABLES // 27 28 // π / 180.0 29 var PI_DIV_180 = float64ToFloat32( 1.7453292519943295e-2 ); 30 31 32 // MAIN // 33 34 /** 35 * Converts an angle from degrees to radians (single-precision). 36 * 37 * @param {number} x - angle in degrees 38 * @returns {number} angle in radians 39 * 40 * @example 41 * var r = deg2radf( 90.0 ); 42 * // returns ~1.571 43 * 44 * @example 45 * var r = deg2radf( -45.0 ); 46 * // returns ~-0.785 47 * 48 * @example 49 * var r = deg2radf( NaN ); 50 * // returns NaN 51 */ 52 function deg2radf( x ) { 53 return float64ToFloat32( x * PI_DIV_180 ); 54 } 55 56 57 // EXPORTS // 58 59 module.exports = deg2radf;