|
| 1 | +<!-- |
| 2 | +
|
| 3 | +@license Apache-2.0 |
| 4 | +
|
| 5 | +Copyright (c) 2024 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 | +# isIntegerf |
| 22 | + |
| 23 | +> Test if a finite [single-precision floating-point number][ieee754] is an integer. |
| 24 | +
|
| 25 | +<section class="usage"> |
| 26 | + |
| 27 | +## Usage |
| 28 | + |
| 29 | +```javascript |
| 30 | +var isIntegerf = require( '@stdlib/math/base/assert/is-integerf' ); |
| 31 | +``` |
| 32 | + |
| 33 | +#### isIntegerf( x ) |
| 34 | + |
| 35 | +Tests if a finite [single-precision floating-point number][ieee754] is an integer. |
| 36 | + |
| 37 | +```javascript |
| 38 | +var bool = isIntegerf( 1.0 ); |
| 39 | +// returns true |
| 40 | +``` |
| 41 | + |
| 42 | +</section> |
| 43 | + |
| 44 | +<!-- /.usage --> |
| 45 | + |
| 46 | +<section class="notes"> |
| 47 | + |
| 48 | +## Notes |
| 49 | + |
| 50 | +- The function assumes a **finite** number. If provided positive or negative `infinity`, the function will return `true`, when, in fact, the result is undefined. If `x` can be `infinite`, wrap the implementation as follows: |
| 51 | + |
| 52 | + ```javascript |
| 53 | + function check( x ) { |
| 54 | + return ( |
| 55 | + x < Infinity && |
| 56 | + x > -Infinity && |
| 57 | + isIntegerf( x ) |
| 58 | + ); |
| 59 | + } |
| 60 | + |
| 61 | + var bool = check( Infinity ); |
| 62 | + // returns false |
| 63 | + |
| 64 | + bool = check( -Infinity ); |
| 65 | + // returns false |
| 66 | + ``` |
| 67 | + |
| 68 | +</section> |
| 69 | + |
| 70 | +<!-- /.notes --> |
| 71 | + |
| 72 | +<section class="examples"> |
| 73 | + |
| 74 | +## Examples |
| 75 | + |
| 76 | +<!-- eslint no-undef: "error" --> |
| 77 | + |
| 78 | +```javascript |
| 79 | +var isIntegerf = require( '@stdlib/math/base/assert/is-integerf' ); |
| 80 | +
|
| 81 | +var bool = isIntegerf( -5.0 ); |
| 82 | +// returns true |
| 83 | +
|
| 84 | +bool = isIntegerf( 3.14 ); |
| 85 | +// returns false |
| 86 | +
|
| 87 | +bool = isIntegerf( NaN ); |
| 88 | +// returns false |
| 89 | +``` |
| 90 | + |
| 91 | +</section> |
| 92 | + |
| 93 | +<!-- /.examples --> |
| 94 | + |
| 95 | +<!-- C interface documentation. --> |
| 96 | + |
| 97 | +* * * |
| 98 | + |
| 99 | +<section class="c"> |
| 100 | + |
| 101 | +## C APIs |
| 102 | + |
| 103 | +<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> |
| 104 | + |
| 105 | +<section class="intro"> |
| 106 | + |
| 107 | +</section> |
| 108 | + |
| 109 | +<!-- /.intro --> |
| 110 | + |
| 111 | +<!-- C usage documentation. --> |
| 112 | + |
| 113 | +<section class="usage"> |
| 114 | + |
| 115 | +### Usage |
| 116 | + |
| 117 | +```c |
| 118 | +#include "stdlib/math/base/assert/is_integerf.h" |
| 119 | +``` |
| 120 | + |
| 121 | +#### stdlib_base_is_integerf( x ) |
| 122 | + |
| 123 | +Tests if a finite [single-precision floating-point number][ieee754] is an integer. |
| 124 | + |
| 125 | +```c |
| 126 | +bool out = stdlib_base_is_integerf( 1.0 ); |
| 127 | +// returns true |
| 128 | +
|
| 129 | +out = stdlib_base_is_integerf( 3.14 ); |
| 130 | +// returns false |
| 131 | +``` |
| 132 | + |
| 133 | +The function accepts the following arguments: |
| 134 | + |
| 135 | +- **x**: `[in] float` input value. |
| 136 | + |
| 137 | +```c |
| 138 | +bool stdlib_base_is_integerf( const float x ); |
| 139 | +``` |
| 140 | +
|
| 141 | +</section> |
| 142 | +
|
| 143 | +<!-- /.usage --> |
| 144 | +
|
| 145 | +<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 146 | +
|
| 147 | +<section class="notes"> |
| 148 | +
|
| 149 | +</section> |
| 150 | +
|
| 151 | +<!-- /.notes --> |
| 152 | +
|
| 153 | +<!-- C API usage examples. --> |
| 154 | +
|
| 155 | +<section class="examples"> |
| 156 | +
|
| 157 | +### Examples |
| 158 | +
|
| 159 | +```c |
| 160 | +#include "stdlib/math/base/assert/is_integerf.h" |
| 161 | +#include <stdio.h> |
| 162 | +#include <stdlib.h> |
| 163 | +#include <stdbool.h> |
| 164 | + |
| 165 | +int main( void ) { |
| 166 | + float x; |
| 167 | + bool v; |
| 168 | + int i; |
| 169 | + |
| 170 | + for ( i = 0; i < 100; i++ ) { |
| 171 | + x = ( ( (float)rand() / (float)RAND_MAX ) * 100.0f ) - 50.0f; |
| 172 | + v = stdlib_base_is_integerf( x ); |
| 173 | + printf( "x = %f, is_integerf(x) = %s\n", x, ( v ) ? "true" : "false" ); |
| 174 | + } |
| 175 | +} |
| 176 | +``` |
| 177 | +
|
| 178 | +</section> |
| 179 | +
|
| 180 | +<!-- /.examples --> |
| 181 | +
|
| 182 | +</section> |
| 183 | +
|
| 184 | +<!-- /.c --> |
| 185 | +
|
| 186 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 187 | +
|
| 188 | +<section class="related"> |
| 189 | +
|
| 190 | +</section> |
| 191 | +
|
| 192 | +<!-- /.related --> |
| 193 | +
|
| 194 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 195 | +
|
| 196 | +<section class="links"> |
| 197 | +
|
| 198 | +[ieee754]: https://en.wikipedia.org/wiki/IEEE_754-1985 |
| 199 | +
|
| 200 | +</section> |
| 201 | +
|
| 202 | +<!-- /.links --> |
0 commit comments