README.md (3133B)
1 <!-- 2 3 @license Apache-2.0 4 5 Copyright (c) 2020 The Stdlib Authors. 6 7 Licensed under the Apache License, Version 2.0 (the "License"); 8 you may not use this file except in compliance with the License. 9 You may obtain a copy of the License at 10 11 http://www.apache.org/licenses/LICENSE-2.0 12 13 Unless required by applicable law or agreed to in writing, software 14 distributed under the License is distributed on an "AS IS" BASIS, 15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 See the License for the specific language governing permissions and 17 limitations under the License. 18 19 --> 20 21 # abs2f 22 23 > Compute the squared [absolute value][absolute-value] of a single-precision floating-point number. 24 25 <section class="intro"> 26 27 </section> 28 29 <!-- /.intro --> 30 31 <section class="usage"> 32 33 ## Usage 34 35 ```javascript 36 var abs2f = require( '@stdlib/math/base/special/abs2f' ); 37 ``` 38 39 #### abs2f( x ) 40 41 Computes the squared [absolute value][absolute-value] of a single-precision floating-point number. 42 43 ```javascript 44 var v = abs2f( -1.0 ); 45 // returns 1.0 46 47 v = abs2f( 2.0 ); 48 // returns 4.0 49 50 v = abs2f( 0.0 ); 51 // returns 0.0 52 53 v = abs2f( -0.0 ); 54 // returns 0.0 55 56 v = abs2f( NaN ); 57 // returns NaN 58 ``` 59 60 </section> 61 62 <!-- /.usage --> 63 64 <section class="examples"> 65 66 ## Examples 67 68 <!-- eslint no-undef: "error" --> 69 70 ```javascript 71 var randu = require( '@stdlib/random/base/randu' ); 72 var round = require( '@stdlib/math/base/special/round' ); 73 var abs2f = require( '@stdlib/math/base/special/abs2f' ); 74 75 var x; 76 var i; 77 78 for ( i = 0; i < 100; i++ ) { 79 x = round( randu() * 100.0 ) - 50.0; 80 console.log( 'abs2f(%d) = %d', x, abs2f( x ) ); 81 } 82 ``` 83 84 </section> 85 86 <!-- /.examples --> 87 88 <!-- C interface documentation. --> 89 90 * * * 91 92 <section class="c"> 93 94 ## C APIs 95 96 <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> 97 98 <section class="intro"> 99 100 </section> 101 102 <!-- /.intro --> 103 104 <!-- C usage documentation. --> 105 106 <section class="usage"> 107 108 ### Usage 109 110 ```c 111 #include "stdlib/math/base/special/abs2f.h" 112 ``` 113 114 #### stdlib_base_abs2f( x ) 115 116 Computes the squared absolute value of a single-precision floating-point number. 117 118 ```c 119 float y = stdlib_base_abs2f( -5.0f ); 120 // returns 25.0f 121 ``` 122 123 The function accepts the following arguments: 124 125 - **x**: `[in] float` input value. 126 127 ```c 128 float stdlib_base_abs2f( const float x ); 129 ``` 130 131 </section> 132 133 <!-- /.usage --> 134 135 <!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 136 137 <section class="notes"> 138 139 </section> 140 141 <!-- /.notes --> 142 143 <!-- C API usage examples. --> 144 145 <section class="examples"> 146 147 ### Examples 148 149 ```c 150 #include "stdlib/math/base/special/abs2f.h" 151 #include <stdio.h> 152 153 int main() { 154 float x[] = { 3.14f, -3.14f, 0.0f, 0.0f/0.0f }; 155 156 float y; 157 int i; 158 for ( i = 0; i < 4; i++ ) { 159 y = stdlib_base_abs2f( x[ i ] ); 160 printf( "abs2f(%f) = %f\n", x[ i ], y ); 161 } 162 } 163 ``` 164 165 </section> 166 167 <!-- /.examples --> 168 169 </section> 170 171 <!-- /.c --> 172 173 <section class="links"> 174 175 [absolute-value]: https://en.wikipedia.org/wiki/Absolute_value 176 177 </section> 178 179 <!-- /.links -->