diff --git a/LICENSE b/LICENSE index 0273186f2..9f357146a 100644 --- a/LICENSE +++ b/LICENSE @@ -181,6 +181,28 @@ The library links against the following external libraries or contains implementations from the following external libraries, which have their own licenses: +* Cephes + +Copyright (c) 1984-2000 Stephen L. Moshier + +Some software in this archive may be from the book _Methods and Programs for +Mathematical Functions_ (Prentice-Hall or Simon & Schuster International, 1989) +or from the Cephes Mathematical Library, a commercial product. In either event, +it is copyrighted by the author. What you see here may be used freely but it +comes with no support or guarantee. + +Stephen L. Moshier +moshier@na-net.ornl.gov + +* FreeBSD + +Copyright (C) 1993-2004 by Sun Microsystems, Inc. All rights reserved. + +Developed at SunPro, a Sun Microsystems, Inc. business. +Permission to use, copy, modify, and distribute this +software is freely granted, provided that this notice +is preserved. + * Boost Boost Software License - Version 1.0 - August 17th, 2003 @@ -207,27 +229,9 @@ FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* FreeBSD - -Copyright (C) 1993-2004 by Sun Microsystems, Inc. All rights reserved. - -Developed at SunPro, a Sun Microsystems, Inc. business. -Permission to use, copy, modify, and distribute this -software is freely granted, provided that this notice -is preserved. - -* Cephes - -Copyright (c) 1984-2000 Stephen L. Moshier - -Some software in this archive may be from the book _Methods and Programs for -Mathematical Functions_ (Prentice-Hall or Simon & Schuster International, 1989) -or from the Cephes Mathematical Library, a commercial product. In either event, -it is copyrighted by the author. What you see here may be used freely but it -comes with no support or guarantee. +* SLATEC Common Mathematical Library -Stephen L. Moshier -moshier@na-net.ornl.gov +Public domain. * FDLIBM @@ -260,6 +264,40 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + +* Faddeeva + +Copyright (c) 2012 Massachusetts Institute of Technology + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * Go Copyright (c) 2009 The Go Authors. All rights reserved. @@ -290,33 +328,3 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -* SLATEC Common Mathematical Library - -Public domain. - -* Faddeeva - -Copyright (c) 2012 Massachusetts Institute of Technology - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - diff --git a/base/special/cround/README.md b/base/special/cround/README.md index 66766a1ab..5ec9d15f3 100644 --- a/base/special/cround/README.md +++ b/base/special/cround/README.md @@ -18,9 +18,9 @@ limitations under the License. --> -# Round +# cround -> Round a complex number to the nearest integer. +> Round each component of a double-precision complex floating-point number to the nearest integer.
@@ -30,36 +30,50 @@ limitations under the License. var cround = require( '@stdlib/math/base/special/cround' ); ``` -#### cround( \[out,] re, im ) +#### cround( z ) -Rounds a `complex` number comprised of a **real** component `re` and an **imaginary** component `im` to the nearest integer. +Rounds each component of a double-precision complex floating-point number to the nearest integer. ```javascript -var v = cround( -4.2, 5.5 ); -// returns [ -4.0, 6.0 ] +var Complex128 = require( '@stdlib/complex/float64' ); +var real = require( '@stdlib/complex/real' ); +var imag = require( '@stdlib/complex/imag' ); -v = cround( 9.99999, 0.1 ); -// returns [ 10.0, 0.0 ] +var v = cround( new Complex128( -4.2, 5.5 ) ); +// returns -v = cround( 0.0, 0.0 ); -// returns [ 0.0, 0.0 ] +var re = real( v ); +// returns -4.0 -v = cround( NaN, NaN ); -// returns [ NaN, NaN ] -``` +var im = imag( v ); +// returns 6.0 -By default, the function returns real and imaginary components as a two-element `array`. To avoid unnecessary memory allocation, the function supports providing an output (destination) object. +v = cround( new Complex128( 9.99999, 0.1 ) ); +// returns -```javascript -var Float64Array = require( '@stdlib/array/float64' ); +re = real( v ); +// returns 10.0 + +im = imag( v ); +// returns 0.0 + +v = cround( new Complex128( 0.0, 0.0 ) ); +// returns + +re = real( v ); +// returns 0.0 -var out = new Float64Array( 2 ); +im = imag( v ); +// returns 0.0 -var v = cround( out, -4.2, 5.5 ); -// returns [ -4.0, 6.0 ] +v = cround( new Complex128( NaN, NaN ) ); +// returns -var bool = ( v === out ); -// returns true +re = real( v ); +// returns NaN + +im = imag( v ); +// returns NaN ```
@@ -73,26 +87,17 @@ var bool = ( v === out ); ```javascript +var uniform = require( '@stdlib/random/base/uniform' ).factory; var Complex128 = require( '@stdlib/complex/float64' ); -var randu = require( '@stdlib/random/base/randu' ); -var real = require( '@stdlib/complex/real' ); -var imag = require( '@stdlib/complex/imag' ); var cround = require( '@stdlib/math/base/special/cround' ); -var re; -var im; +var rand = uniform( -50.0, 50.0 ); + var z; -var o; -var w; var i; - for ( i = 0; i < 100; i++ ) { - re = ( randu()*100.0 ) - 50.0; - im = ( randu()*100.0 ) - 50.0; - z = new Complex128( re, im ); - o = cround( real(z), imag(z) ); - w = new Complex128( o[ 0 ], o[ 1 ] ); - console.log( 'round(%s) = %s', z.toString(), w.toString() ); + z = new Complex128( rand(), rand() ); + console.log( 'cround(%s) = %s', z, cround( z ) ); } ``` @@ -100,6 +105,117 @@ for ( i = 0; i < 100; i++ ) { + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/math/base/special/cround.h" +``` + +#### stdlib_base_cround( z ) + +Rounds each component of a double-precision complex floating-point number to the nearest integer. + +```c +#include "stdlib/complex/float64.h" +#include "stdlib/complex/real.h" +#include "stdlib/complex/imag.h" + +stdlib_complex128_t z = stdlib_complex128( -4.2, 5.5 ); + +stdlib_complex128_t out = stdlib_base_cround( z ); + +double re = stdlib_real( out ); +// returns -4.0 + +double im = stdlib_imag( out ); +// returns 6.0 +``` + +The function accepts the following arguments: + +- **z**: `[in] stdlib_complex128_t` input value. + +```c +stdlib_complex128_t stdlib_base_cround( const stdlib_complex128_t z ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/math/base/special/cround.h" +#include "stdlib/complex/float64.h" +#include "stdlib/complex/reim.h" +#include + +int main( void ) { + const stdlib_complex128_t x[] = { + stdlib_complex128( 3.14, 1.5 ), + stdlib_complex128( -3.14, -1.5 ), + stdlib_complex128( 0.0, 0.0 ), + stdlib_complex128( 0.0/0.0, 0.0/0.0 ) + }; + + stdlib_complex128_t v; + stdlib_complex128_t y; + double re1; + double im1; + double re2; + double im2; + int i; + for ( i = 0; i < 4; i++ ) { + v = x[ i ]; + y = stdlib_base_cround( v ); + stdlib_reim( v, &re1, &im1 ); + stdlib_reim( y, &re2, &im2 ); + printf( "cround(%lf + %lfi) = %lf + %lfi\n", re1, im1, re2, im2 ); + } +} +``` + +
+ + + +
+ + +