README.md (3928B)
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 # sizeOf 22 23 > Return the size (in bytes) of the canonical binary representation of a specified numeric type. 24 25 <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> 26 27 <section class="intro"> 28 29 </section> 30 31 <!-- /.intro --> 32 33 <!-- Package usage documentation. --> 34 35 <section class="usage"> 36 37 ## Usage 38 39 ```javascript 40 var sizeOf = require( '@stdlib/utils/size-of' ); 41 ``` 42 43 #### sizeOf( dtype ) 44 45 Returns the size (in bytes) of the canonical binary representation of a specified numeric type. 46 47 ```javascript 48 var s = sizeOf( 'int8' ); 49 // returns 1 50 ``` 51 52 The following numeric types are supported: 53 54 - `float64`: double-precision floating-point numbers 55 - `float32`: single-precision floating-point numbers 56 - `float16`: half-precision floating-point numbers 57 - `int32`: 32-bit two's complement signed integers 58 - `uint32`: 32-bit unsigned integers 59 - `int16`: 16-bit two's complement signed integers 60 - `uint16`: 16-bit unsigned integers 61 - `int8`: 8-bit two's complement signed integers 62 - `uint8`: 8-bit unsigned integers 63 - `uint8c`: 8-bit unsigned integers clamped to `0-255` 64 - `complex128`: 128-bit complex numbers 65 - `complex64`: 64-bit complex numbers 66 67 </section> 68 69 <!-- /.usage --> 70 71 <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 72 73 <section class="notes"> 74 75 </section> 76 77 <!-- /.notes --> 78 79 <!-- Package usage examples. --> 80 81 <section class="examples"> 82 83 ## Examples 84 85 <!-- eslint no-undef: "error" --> 86 87 ```javascript 88 var sizeOf = require( '@stdlib/utils/size-of' ); 89 90 var s = sizeOf( 'float64' ); 91 // returns 8 92 93 s = sizeOf( 'float32' ); 94 // returns 4 95 96 s = sizeOf( 'float16' ); 97 // returns 2 98 99 s = sizeOf( 'int32' ); 100 // returns 4 101 102 s = sizeOf( 'uint32' ); 103 // returns 4 104 105 s = sizeOf( 'int16' ); 106 // returns 2 107 108 s = sizeOf( 'uint16' ); 109 // returns 2 110 111 s = sizeOf( 'int8' ); 112 // returns 1 113 114 s = sizeOf( 'uint8' ); 115 // returns 1 116 117 s = sizeOf( 'uint8c' ); 118 // returns 1 119 120 s = sizeOf( 'complex128' ); 121 // returns 16 122 123 s = sizeOf( 'complex64' ); 124 // returns 8 125 ``` 126 127 </section> 128 129 <!-- /.examples --> 130 131 <!-- Section for describing a command-line interface. --> 132 133 * * * 134 135 <section class="cli"> 136 137 ## CLI 138 139 <!-- CLI usage documentation. --> 140 141 <section class="usage"> 142 143 ### Usage 144 145 ```text 146 Usage: sizeof [options] <dtype> 147 148 Options: 149 150 -h, --help Print this message. 151 -V, --version Print the package version. 152 ``` 153 154 </section> 155 156 <!-- /.usage --> 157 158 <!-- CLI usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 159 160 <section class="notes"> 161 162 </section> 163 164 <!-- /.notes --> 165 166 <!-- CLI usage examples. --> 167 168 <section class="examples"> 169 170 ### Examples 171 172 ```bash 173 $ sizeof int16 174 2 175 ``` 176 177 </section> 178 179 <!-- /.examples --> 180 181 </section> 182 183 <!-- /.cli --> 184 185 <!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 186 187 <section class="references"> 188 189 </section> 190 191 <!-- /.references --> 192 193 <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 194 195 <section class="links"> 196 197 </section> 198 199 <!-- /.links -->