Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 61 additions & 19 deletions lib/node_modules/@stdlib/math/base/special/cfloor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ limitations under the License.

-->

# Floor
# cfloor

> Round a double-precision complex floating-point number toward negative infinity.
> Round each component of a double-precision complex floating-point number toward negative infinity.

<section class="intro">

Expand Down Expand Up @@ -51,7 +51,7 @@ var cfloor = require( '@stdlib/math/base/special/cfloor' );

#### cfloor( z )

Rounds a double-precision complex floating-point number toward negative infinity.
Rounds each component of a double-precision complex floating-point number toward negative infinity.

```javascript
var Complex128 = require( '@stdlib/complex/float64/ctor' );
Expand All @@ -69,6 +69,55 @@ v = cfloor( new Complex128( NaN, NaN ) );
// returns <Complex128>[ NaN, NaN ]
```

#### cfloor.assign( re, im, out, strideOut, offsetOut )

Rounds each component of a double-precision complex floating-point number toward negative infinity and assigns results to a provided output array.

```javascript
var Float64Array = require( '@stdlib/array/float64' );

var out = new Float64Array( 2 );
var v = cfloor.assign( -1.5, 2.5, out, 1, 0 );
// returns <Float64Array>[ -2.0, 2.0 ]

var bool = ( out === v );
// returns true
```

The function supports the following parameters:

- **re**: real component.
- **im**: imaginary component.
- **out**: output array.
- **strideOut**: stride length for `out`.
- **offsetOut**: starting index for `out`.

#### cfloor.strided( z, sz, oz, out, so, oo )

Rounds each component of a double-precision complex floating-point number stored in a real-valued strided array view toward negative infinity and assigns results to a provided strided output array.

```javascript
var Float64Array = require( '@stdlib/array/float64' );

var z = new Float64Array( [ -1.5, 2.5 ] );
var out = new Float64Array( 2 );

var v = cfloor.strided( z, 1, 0, out, 1, 0 );
// returns <Float64Array>[ -2.0, 2.0 ]

var bool = ( out === v );
// returns true
```

The function supports the following parameters:

- **z**: complex number strided array view.
- **sz**: stride length for `z`.
- **oz**: starting index for `z`.
- **out**: output array.
- **so**: stride length for `out`.
- **oo**: starting index for `out`.

</section>

<!-- /.usage -->
Expand All @@ -80,23 +129,16 @@ v = cfloor( new Complex128( NaN, NaN ) );
<!-- eslint no-undef: "error" -->

```javascript
var Complex128 = require( '@stdlib/complex/float64/ctor' );
var randu = require( '@stdlib/random/base/randu' );
var Complex128Array = require( '@stdlib/array/complex128' );
var uniform = require( '@stdlib/random/array/uniform' );
var logEachMap = require( '@stdlib/console/log-each-map' );
var cfloor = require( '@stdlib/math/base/special/cfloor' );

var re;
var im;
var z;
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 );
w = cfloor( z );
console.log( 'floor(%s) = %s', z.toString(), w.toString() );
}
// Create an array of random numbers:
var arr = new Complex128Array( uniform( 200, -50.0, 50.0 ) );

// Round each component of each complex number toward negative infinity:
logEachMap( 'cfloor(%s) = %s', arr, cfloor );
```

</section>
Expand Down Expand Up @@ -131,7 +173,7 @@ for ( i = 0; i < 100; i++ ) {

#### stdlib_base_cfloor( z )

Rounds a double-precision complex floating-point number toward negative infinity.
Rounds each component of a double-precision complex floating-point number toward negative infinity.

```c
#include "stdlib/complex/float64/ctor.h"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2026 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var bench = require( '@stdlib/bench' );
var uniform = require( '@stdlib/random/array/uniform' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var Float64Array = require( '@stdlib/array/float64' );
var format = require( '@stdlib/string/format' );
var pkg = require( './../package.json' ).name;
var assign = require( './../lib' ).assign;


// VARIABLES //

var options = {
'dtype': 'float64'
};


// MAIN //

bench( format( '%s:assign', pkg ), function benchmark( b ) {
var out;
var re;
var im;
var N;
var i;
var j;

N = 100;
re = uniform( N, -500.0, 500.0, options );
im = uniform( N, -500.0, 500.0, options );

out = new Float64Array( 2 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
j = i % N;
out = assign( re[ j ], im[ j ], out, 1, 0 );
if ( typeof out !== 'object' ) {
b.fail( 'should return an object' );
}
}
b.toc();
if ( isnan( out[ 0 ] ) || isnan( out[ 1 ] ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
b.end();
});
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,36 @@
// MODULES //

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/array/uniform' );
var uniform = require( '@stdlib/random/array/uniform' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var Complex128 = require( '@stdlib/complex/float64/ctor' );
var Complex128Array = require( '@stdlib/array/complex128' );
var real = require( '@stdlib/complex/float64/real' );
var imag = require( '@stdlib/complex/float64/imag' );
var uniform = require( '@stdlib/random/base/uniform' );
var isArray = require( '@stdlib/assert/is-array' );
var floor = require( '@stdlib/math/base/special/floor' );
var format = require( '@stdlib/string/format' );
var pkg = require( './../package.json' ).name;
var cfloor = require( './../lib' );


// VARIABLES //

var options = {
'dtype': 'float64'
};


// MAIN //

bench( pkg, function benchmark( b ) {
var values;
var zbuf;
var z;
var y;
var i;

values = [
new Complex128( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) ),
new Complex128( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) )
];
zbuf = uniform( 200, -500.0, 500.0, options );
z = new Complex128Array( zbuf.buffer );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
y = cfloor( ( values[ i%values.length ] ) );
y = cfloor( z.get( i%100 ) );
if ( isnan( real( y ) ) ) {
b.fail( 'should not return NaN' );
}
Expand All @@ -60,27 +62,3 @@ bench( pkg, function benchmark( b ) {
b.pass( 'benchmark finished' );
b.end();
});

bench( format( '%s::manual', pkg ), function benchmark( b ) {
var re;
var im;
var y;
var i;

re = randu( 10, -500.0, 500.0 );
im = randu( 10, -500.0, 500.0 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
y = [ floor( re[ i%re.length ] ), floor( im[ i%im.length ] ) ];
if ( y.length === 0 ) {
b.fail( 'should not be empty' );
}
}
b.toc();
if ( !isArray( y ) ) {
b.fail( 'should return an array' );
}
b.pass( 'benchmark finished' );
b.end();
});
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@

var resolve = require( 'path' ).resolve;
var bench = require( '@stdlib/bench' );
var uniform = require( '@stdlib/random/base/uniform' );
var uniform = require( '@stdlib/random/array/uniform' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var Complex128 = require( '@stdlib/complex/float64/ctor' );
var Complex128Array = require( '@stdlib/array/complex128' );
var real = require( '@stdlib/complex/float64/real' );
var imag = require( '@stdlib/complex/float64/imag' );
var tryRequire = require( '@stdlib/utils/try-require' );
var format = require( '@stdlib/string/format' );
var pkg = require( './../package.json' ).name;
Expand All @@ -37,29 +38,31 @@ var cfloor = tryRequire( resolve( __dirname, './../lib/native.js' ) );
var opts = {
'skip': ( cfloor instanceof Error )
};
var options = {
'dtype': 'float64'
};


// MAIN //

bench( format( '%s::native', pkg ), opts, function benchmark( b ) {
var values;
var zbuf;
var z;
var y;
var i;

values = [
new Complex128( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) ),
new Complex128( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) )
];
zbuf = uniform( 200, -500.0, 500.0, options );
z = new Complex128Array( zbuf.buffer );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
y = cfloor( values[ i%values.length ] );
y = cfloor( z.get( i%100 ) );
if ( isnan( real( y ) ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnan( real( y ) ) ) {
if ( isnan( imag( y ) ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2026 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var bench = require( '@stdlib/bench' );
var uniform = require( '@stdlib/random/array/uniform' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var Float64Array = require( '@stdlib/array/float64' );
var format = require( '@stdlib/string/format' );
var pkg = require( './../package.json' ).name;
var strided = require( './../lib' ).strided;


// VARIABLES //

var options = {
'dtype': 'float64'
};


// MAIN //

bench( format( '%s:strided', pkg ), function benchmark( b ) {
var out;
var z;
var N;
var i;
var j;

N = 50;
z = uniform( N*2, -500.0, 500.0, options );

out = new Float64Array( 2 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
j = ( i % N ) * 2;
out = strided( z, 1, j, out, 1, 0 );
if ( typeof out !== 'object' ) {
b.fail( 'should return an object' );
}
}
b.toc();
if ( isnan( out[ 0 ] ) || isnan( out[ 1 ] ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
b.end();
});
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
#include <stdio.h>
#include <math.h>
#include <complex.h>
#include <time.h>
#include <sys/time.h>

#define NAME "floor"
#define NAME "cfloor"
#define ITERATIONS 1000000
#define REPEATS 3

Expand Down
Loading
Loading