README.md (4834B)
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 # Complex128 22 23 > 128-bit complex number. 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 Complex128 = require( '@stdlib/complex/float64' ); 41 ``` 42 43 #### Complex128( real, imag ) 44 45 128-bit complex number constructor, where `real` and `imag` are the **real** and **imaginary** components, respectively. 46 47 ```javascript 48 var z = new Complex128( 5.0, 3.0 ); 49 // returns <Complex128> 50 ``` 51 52 * * * 53 54 ## Properties 55 56 #### Complex128.BYTES_PER_ELEMENT 57 58 Size (in bytes) of each component. 59 60 ```javascript 61 var nbytes = Complex128.BYTES_PER_ELEMENT; 62 // returns 8 63 ``` 64 65 #### Complex128.prototype.BYTES_PER_ELEMENT 66 67 Size (in bytes) of each component. 68 69 ```javascript 70 var z = new Complex128( 5.0, 3.0 ); 71 72 var nbytes = z.BYTES_PER_ELEMENT; 73 // returns 8 74 ``` 75 76 #### Complex128.prototype.byteLength 77 78 Length (in bytes) of a complex number. 79 80 ```javascript 81 var z = new Complex128( 5.0, 3.0 ); 82 83 var nbytes = z.byteLength; 84 // returns 16 85 ``` 86 87 ### Instance 88 89 A `Complex128` instance has the following properties... 90 91 #### re 92 93 A **read-only** property returning the **real** component. 94 95 ```javascript 96 var z = new Complex128( 5.0, 3.0 ); 97 98 var re = z.re; 99 // returns 5.0 100 ``` 101 102 #### im 103 104 A **read-only** property returning the **imaginary** component. 105 106 ```javascript 107 var z = new Complex128( 5.0, -3.0 ); 108 109 var im = z.im; 110 // returns -3.0 111 ``` 112 113 * * * 114 115 ## Methods 116 117 ### Accessor Methods 118 119 These methods do **not** mutate a `Complex128` instance and, instead, return a complex number representation. 120 121 #### Complex128.prototype.toString() 122 123 Returns a `string` representation of a `Complex128` instance. 124 125 ```javascript 126 var z = new Complex128( 5.0, 3.0 ); 127 var str = z.toString(); 128 // returns '5 + 3i' 129 130 z = new Complex128( -5.0, -3.0 ); 131 str = z.toString(); 132 // returns '-5 - 3i' 133 ``` 134 135 #### Complex128.prototype.toJSON() 136 137 Returns a [JSON][json] representation of a `Complex128` instance. [`JSON.stringify()`][mdn-json-stringify] implicitly calls this method when stringifying a `Complex128` instance. 138 139 ```javascript 140 var z = new Complex128( 5.0, -3.0 ); 141 142 var o = z.toJSON(); 143 /* 144 { 145 "type": "Complex128", 146 "re": 5.0, 147 "im": -3.0 148 } 149 */ 150 ``` 151 152 To [revive][mdn-json-parse] a `Complex128` number from a [JSON][json] `string`, see [@stdlib/complex/reviver-float64][@stdlib/complex/reviver-float64]. 153 154 </section> 155 156 <!-- /.usage --> 157 158 * * * 159 160 <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 161 162 <section class="notes"> 163 164 ## Notes 165 166 - Both the **real** and **imaginary** components are stored as double-precision floating-point numbers. 167 168 </section> 169 170 <!-- /.notes --> 171 172 * * * 173 174 <!-- Package usage examples. --> 175 176 <section class="examples"> 177 178 ## Examples 179 180 <!-- eslint no-undef: "error" --> 181 182 ```javascript 183 var Complex128 = require( '@stdlib/complex/float64' ); 184 185 var z = new Complex128( 3.0, -2.0 ); 186 187 console.log( 'type: %s', typeof z ); 188 // => type: object 189 190 console.log( 'str: %s', z ); 191 // => str: 3 - 2i 192 193 console.log( 'real: %d', z.re ); 194 // => real: 3.0 195 196 console.log( 'imag: %d', z.im ); 197 // => imag: -2.0 198 199 console.log( 'JSON: %s', JSON.stringify( z ) ); 200 // => JSON: {"type":"Complex128","re":3,"im":-2} 201 ``` 202 203 </section> 204 205 <!-- /.examples --> 206 207 <!-- 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. --> 208 209 <section class="references"> 210 211 </section> 212 213 <!-- /.references --> 214 215 <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 216 217 <section class="links"> 218 219 [json]: http://www.json.org/ 220 221 [mdn-json-stringify]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify 222 223 [mdn-json-parse]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse 224 225 [@stdlib/complex/reviver-float64]: https://www.npmjs.com/package/@stdlib/complex/tree/main/reviver-float64 226 227 </section> 228 229 <!-- /.links -->