README.md (2148B)
1 <!-- 2 3 @license Apache-2.0 4 5 Copyright (c) 2018 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 # isOdd 22 23 > Test if a finite numeric value is an odd number. 24 25 <section class="usage"> 26 27 ## Usage 28 29 ```javascript 30 var isOdd = require( '@stdlib/math/base/assert/is-odd' ); 31 ``` 32 33 #### isOdd( x ) 34 35 Tests if a **finite** `numeric` value is an odd number. 36 37 ```javascript 38 var bool = isOdd( 5.0 ); 39 // returns true 40 41 bool = isOdd( -2.0 ); 42 // returns false 43 44 bool = isOdd( 0.0 ); 45 // returns false 46 47 bool = isOdd( NaN ); 48 // returns false 49 ``` 50 51 </section> 52 53 <!-- /.usage --> 54 55 <section class="notes"> 56 57 ## Notes 58 59 - 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: 60 61 ```javascript 62 function check( x ) { 63 return ( 64 x < Infinity && 65 x > -Infinity && 66 isOdd( x ) 67 ); 68 } 69 70 var bool = check( Infinity ); 71 // returns false 72 73 bool = check( -Infinity ); 74 // returns false 75 ``` 76 77 </section> 78 79 <!-- /.notes --> 80 81 <section class="examples"> 82 83 ## Examples 84 85 <!-- eslint no-undef: "error" --> 86 87 ```javascript 88 var randu = require( '@stdlib/random/base/randu' ); 89 var round = require( '@stdlib/math/base/special/round' ); 90 var isOdd = require( '@stdlib/math/base/assert/is-odd' ); 91 92 var bool; 93 var x; 94 var i; 95 96 for ( i = 0; i < 100; i++ ) { 97 x = round( randu()*100.0 ); 98 bool = isOdd( x ); 99 console.log( '%d is %s', x, ( bool ) ? 'odd' : 'not odd' ); 100 } 101 ``` 102 103 </section> 104 105 <!-- /.examples --> 106 107 <section class="links"> 108 109 </section> 110 111 <!-- /.links -->