README.md (2163B)
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 # isEven 22 23 > Test if a finite numeric value is an even number. 24 25 <section class="usage"> 26 27 ## Usage 28 29 ```javascript 30 var isEven = require( '@stdlib/math/base/assert/is-even' ); 31 ``` 32 33 #### isEven( x ) 34 35 Tests if a **finite** `numeric` value is an even number. 36 37 ```javascript 38 var bool = isEven( 5.0 ); 39 // returns false 40 41 bool = isEven( -2.0 ); 42 // returns true 43 44 bool = isEven( 0.0 ); 45 // returns true 46 47 bool = isEven( 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 isEven( 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 isEven = require( '@stdlib/math/base/assert/is-even' ); 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 = isEven( x ); 99 console.log( '%d is %s', x, ( bool ) ? 'even' : 'not even' ); 100 } 101 ``` 102 103 </section> 104 105 <!-- /.examples --> 106 107 <section class="links"> 108 109 </section> 110 111 <!-- /.links -->