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
66 changes: 57 additions & 9 deletions lib/node_modules/@stdlib/math/base/special/cfloorf/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,55 @@ v = cfloorf( new Complex64( NaN, NaN ) );
// returns <Complex64>[ NaN, NaN ]
```

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

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

```javascript
var Float32Array = require( '@stdlib/array/float32' );

var out = new Float32Array( 2 );
var v = cfloorf.assign( -1.5, 2.5, out, 1, 0 );
// returns <Float32Array>[ -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`.

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

Rounds each component of a single-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 Float32Array = require( '@stdlib/array/float32' );

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

var v = cfloorf.strided( z, 1, 0, out, 1, 0 );
// returns <Float32Array>[ -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,17 +129,16 @@ v = cfloorf( new Complex64( NaN, NaN ) );
<!-- eslint no-undef: "error" -->

```javascript
var Complex64 = require( '@stdlib/complex/float32/ctor' );
var uniform = require( '@stdlib/random/base/uniform' ).factory;
var Complex64Array = require( '@stdlib/array/complex64' );
var uniform = require( '@stdlib/random/array/uniform' );
var logEachMap = require( '@stdlib/console/log-each-map' );
var cfloorf = require( '@stdlib/math/base/special/cfloorf' );

var rand = uniform( -50.0, 50.0 );
var z;
var i;
for ( i = 0; i < 100; i++ ) {
z = new Complex64( rand(), rand() );
console.log( 'cfloorf(%s) = %s', z, cfloorf( z ) );
}
// Create an array of random numbers:
var arr = new Complex64Array( uniform( 200, -50.0, 50.0 ) );

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

</section>
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 isnanf = require( '@stdlib/math/base/assert/is-nanf' );
var Float32Array = require( '@stdlib/array/float32' );
var format = require( '@stdlib/string/format' );
var pkg = require( './../package.json' ).name;
var assign = require( './../lib' ).assign;


// VARIABLES //

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


// 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 Float32Array( 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 ( isnanf( out[ 0 ] ) || isnanf( 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,66 +21,44 @@
// MODULES //

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/array/uniform' );
var uniform = require( '@stdlib/random/array/uniform' );
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
var Complex64 = require( '@stdlib/complex/float32/ctor' );
var real = require( '@stdlib/complex/float32/real' );
var imag = require( '@stdlib/complex/float32/imag' );
var uniform = require( '@stdlib/random/base/uniform' );
var isArray = require( '@stdlib/assert/is-array' );
var floorf = require( '@stdlib/math/base/special/floorf' );
var format = require( '@stdlib/string/format' );
var Complex64Array = require( '@stdlib/array/complex64' );
var realf = require( '@stdlib/complex/float32/real' );
var imagf = require( '@stdlib/complex/float32/imag' );
var pkg = require( './../package.json' ).name;
var cfloorf = require( './../lib' );


// VARIABLES //

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


// MAIN //

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

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

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
y = cfloorf( ( values[ i%values.length ] ) );
if ( isnanf( real( y ) ) ) {
y = cfloorf( z.get( i%100 ) );
if ( isnanf( realf( y ) ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnanf( imag( y ) ) ) {
if ( isnanf( imagf( y ) ) ) {
b.fail( 'should not return NaN' );
}
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 = [ floorf( re[ i % re.length ] ), floorf( 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 isnanf = require( '@stdlib/math/base/assert/is-nanf' );
var Complex64 = require( '@stdlib/complex/float32/ctor' );
var real = require( '@stdlib/complex/float32/real' );
var Complex64Array = require( '@stdlib/array/complex64' );
var realf = require( '@stdlib/complex/float32/real' );
var imagf = require( '@stdlib/complex/float32/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 cfloorf = tryRequire( resolve( __dirname, './../lib/native.js' ) );
var opts = {
'skip': ( cfloorf instanceof Error )
};
var options = {
'dtype': 'float32'
};


// MAIN //

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

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

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
y = cfloorf( values[ i % values.length ] );
if ( isnanf( real( y ) ) ) {
y = cfloorf( z.get( i%100 ) );
if ( isnanf( realf( y ) ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnanf( real( y ) ) ) {
if ( isnanf( imagf( 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 isnanf = require( '@stdlib/math/base/assert/is-nanf' );
var Float32Array = require( '@stdlib/array/float32' );
var format = require( '@stdlib/string/format' );
var pkg = require( './../package.json' ).name;
var strided = require( './../lib' ).strided;


// VARIABLES //

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


// 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 Float32Array( 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 ( isnanf( out[ 0 ] ) || isnanf( 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 @@ -22,7 +22,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <complex.h>
#include <time.h>
#include <sys/time.h>

#define NAME "cfloorf"
Expand Down Expand Up @@ -137,7 +137,7 @@ int main( void ) {

print_version();
for ( i = 0; i < REPEATS; i++ ) {
printf( "# c::%s\n", NAME );
printf( "# c::native::%s\n", NAME );
elapsed = benchmark();
print_results( elapsed );
printf( "ok %d benchmark finished\n", i+1 );
Expand Down
Loading
Loading