Skip to content

Commit 0a3d6a1

Browse files
aayush0325stdlib-botanandkaranubckgryte
authored
refactor!: update math/base/special/cceilf to follow latest project conventions
This commit migrates the `cceilf` interface to operate on stdlib's `stdlib_complex64_t` dtype, rather than the built-in `complex` dtype. BREAKING CHANGE: migrate to `stdlib_complex64_t` To migrate, users should update their usage of `complex` to `stdlib_complex64_t` which is available via `@stdlib/complex/float32/ctor` package. PR-URL: #3400 Closes: #3398 Reviewed-by: Athan Reines <[email protected]> Reviewed-by: Karan Anand <[email protected]> Co-authored-by: stdlib-bot <[email protected]> Co-authored-by: Karan Anand <[email protected]> Co-authored-by: Athan Reines <[email protected]>
1 parent d89509f commit 0a3d6a1

File tree

20 files changed

+970
-51
lines changed

20 files changed

+970
-51
lines changed

lib/node_modules/@stdlib/math/base/special/cceilf/README.md

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ limitations under the License.
2020

2121
# cceilf
2222

23-
> Round a single-precision complex floating-point number toward positive infinity.
23+
> Round each component of a single-precision complex floating-point number toward positive infinity.
2424
2525
<section class="usage">
2626

@@ -32,7 +32,7 @@ var cceilf = require( '@stdlib/math/base/special/cceilf' );
3232

3333
#### cceilf( z )
3434

35-
Rounds a single-precision complex floating-point number toward positive infinity.
35+
Rounds each component of a single-precision complex floating-point number toward positive infinity.
3636

3737
```javascript
3838
var Complex64 = require( '@stdlib/complex/float32/ctor' );
@@ -106,21 +106,30 @@ for ( i = 0; i < 100; i++ ) {
106106

107107
#### stdlib_base_cceilf( z )
108108

109-
Rounds a single-precision complex floating-point number toward positive infinity.
109+
Rounds each component of a single-precision complex floating-point number toward positive infinity.
110110

111111
```c
112-
#include <complex.h>
112+
#include "stdlib/complex/float32/ctor.h"
113+
#include "stdlib/complex/float32/real.h"
114+
#include "stdlib/complex/float32/imag.h"
113115

114-
float complex y = stdlib_base_cceilf( 2.5f-1.5f*I );
115-
// returns 3.0f-1.0f*I
116+
stdlib_complex64_t z = stdlib_complex64( 2.5f, -1.5f );
117+
118+
stdlib_complex64_t out = stdlib_base_cceilf( z );
119+
120+
float re = stdlib_complex64_real( out );
121+
// returns 3.0f
122+
123+
float im = stdlib_complex64_imag( out );
124+
// returns -1.0f
116125
```
117126

118127
The function accepts the following arguments:
119128

120-
- **z**: `[in] float complex` input value.
129+
- **z**: `[in] stdlib_complex64_t` input value.
121130

122131
```c
123-
float complex stdlib_base_cceilf( const float complex z );
132+
stdlib_complex64_t stdlib_base_cceilf( const stdlib_complex64_t z );
124133
```
125134
126135
</section>
@@ -143,19 +152,31 @@ float complex stdlib_base_cceilf( const float complex z );
143152
144153
```c
145154
#include "stdlib/math/base/special/cceilf.h"
155+
#include "stdlib/complex/float32/ctor.h"
156+
#include "stdlib/complex/float32/reim.h"
146157
#include <stdio.h>
147-
#include <complex.h>
148158
149159
int main( void ) {
150-
const float complex x[] = { 3.14f+1.5f*I, -3.14f-1.5f*I, 0.0f+0.0f*I, 0.0f/0.0f+0.0f/0.0f*I };
151-
152-
float complex v;
153-
float complex y;
160+
const stdlib_complex64_t x[] = {
161+
stdlib_complex64( 3.14f, 1.5f ),
162+
stdlib_complex64( -3.14f, -1.5f ),
163+
stdlib_complex64( 0.0f, 0.0f ),
164+
stdlib_complex64( 0.0f/0.0f, 0.0f/0.0f )
165+
};
166+
167+
stdlib_complex64_t v;
168+
stdlib_complex64_t y;
169+
float re1;
170+
float im1;
171+
float re2;
172+
float im2;
154173
int i;
155174
for ( i = 0; i < 4; i++ ) {
156175
v = x[ i ];
157176
y = stdlib_base_cceilf( v );
158-
printf( "cceilf(%f + %fi) = %f + %fi\n", crealf( v ), cimagf( v ), crealf( y ), cimagf( y ) );
177+
stdlib_complex64_reim( v, &re1, &im1 );
178+
stdlib_complex64_reim( y, &re2, &im2 );
179+
printf( "cceilf(%f + %fi) = %f + %fi\n", re1, im1, re2, im2 );
159180
}
160181
}
161182
```
@@ -172,12 +193,6 @@ int main( void ) {
172193

173194
<section class="related">
174195

175-
* * *
176-
177-
## See Also
178-
179-
- <span class="package-name">[`@stdlib/math/base/special/cceil`][@stdlib/math/base/special/cceil]</span><span class="delimiter">: </span><span class="description">round each component of a double-precision complex floating-point number toward positive infinity.</span>
180-
181196
</section>
182197

183198
<!-- /.related -->
@@ -188,8 +203,6 @@ int main( void ) {
188203

189204
<!-- <related-links> -->
190205

191-
[@stdlib/math/base/special/cceil]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/cceil
192-
193206
<!-- </related-links> -->
194207

195208
</section>
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var resolve = require( 'path' ).resolve;
24+
var bench = require( '@stdlib/bench' );
25+
var uniform = require( '@stdlib/random/base/uniform' );
26+
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
27+
var Complex64 = require( '@stdlib/complex/float32/ctor' );
28+
var real = require( '@stdlib/complex/float32/real' );
29+
var imag = require( '@stdlib/complex/float32/imag' );
30+
var tryRequire = require( '@stdlib/utils/try-require' );
31+
var pkg = require( './../package.json' ).name;
32+
33+
34+
// VARIABLES //
35+
36+
var cceilf = tryRequire( resolve( __dirname, './../lib/native.js' ) );
37+
var opts = {
38+
'skip': ( cceilf instanceof Error )
39+
};
40+
41+
42+
// MAIN //
43+
44+
bench( pkg, opts, function benchmark( b ) {
45+
var values;
46+
var y;
47+
var i;
48+
49+
values = [
50+
new Complex64( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) ),
51+
new Complex64( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) )
52+
];
53+
54+
b.tic();
55+
for ( i = 0; i < b.iterations; i++ ) {
56+
y = cceilf( values[ i%values.length ] );
57+
if ( isnanf( real( y ) ) ) {
58+
b.fail( 'should not return NaN' );
59+
}
60+
}
61+
b.toc();
62+
if ( isnanf( imag( y ) ) ) {
63+
b.fail( 'should not return NaN' );
64+
}
65+
b.pass( 'benchmark finished' );
66+
b.end();
67+
});
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
#/
2+
# @license Apache-2.0
3+
#
4+
# Copyright (c) 2025 The Stdlib Authors.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#/
18+
19+
# VARIABLES #
20+
21+
ifndef VERBOSE
22+
QUIET := @
23+
else
24+
QUIET :=
25+
endif
26+
27+
# Determine the OS ([1][1], [2][2]).
28+
#
29+
# [1]: https://en.wikipedia.org/wiki/Uname#Examples
30+
# [2]: http://stackoverflow.com/a/27776822/2225624
31+
OS ?= $(shell uname)
32+
ifneq (, $(findstring MINGW,$(OS)))
33+
OS := WINNT
34+
else
35+
ifneq (, $(findstring MSYS,$(OS)))
36+
OS := WINNT
37+
else
38+
ifneq (, $(findstring CYGWIN,$(OS)))
39+
OS := WINNT
40+
else
41+
ifneq (, $(findstring Windows_NT,$(OS)))
42+
OS := WINNT
43+
endif
44+
endif
45+
endif
46+
endif
47+
48+
# Define the program used for compiling C source files:
49+
ifdef C_COMPILER
50+
CC := $(C_COMPILER)
51+
else
52+
CC := gcc
53+
endif
54+
55+
# Define the command-line options when compiling C files:
56+
CFLAGS ?= \
57+
-std=c99 \
58+
-O3 \
59+
-Wall \
60+
-pedantic
61+
62+
# Determine whether to generate position independent code ([1][1], [2][2]).
63+
#
64+
# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options
65+
# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option
66+
ifeq ($(OS), WINNT)
67+
fPIC ?=
68+
else
69+
fPIC ?= -fPIC
70+
endif
71+
72+
# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`):
73+
INCLUDE ?=
74+
75+
# List of source files:
76+
SOURCE_FILES ?=
77+
78+
# List of libraries (e.g., `-lopenblas -lpthread`):
79+
LIBRARIES ?=
80+
81+
# List of library paths (e.g., `-L /foo/bar -L /beep/boop`):
82+
LIBPATH ?=
83+
84+
# List of C targets:
85+
c_targets := benchmark.out
86+
87+
88+
# RULES #
89+
90+
#/
91+
# Compiles source files.
92+
#
93+
# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`)
94+
# @param {string} [CFLAGS] - C compiler options
95+
# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`)
96+
# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`)
97+
# @param {string} [SOURCE_FILES] - list of source files
98+
# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`)
99+
# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`)
100+
#
101+
# @example
102+
# make
103+
#
104+
# @example
105+
# make all
106+
#/
107+
all: $(c_targets)
108+
109+
.PHONY: all
110+
111+
#/
112+
# Compiles C source files.
113+
#
114+
# @private
115+
# @param {string} CC - C compiler (e.g., `gcc`)
116+
# @param {string} CFLAGS - C compiler options
117+
# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`)
118+
# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`)
119+
# @param {string} SOURCE_FILES - list of source files
120+
# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`)
121+
# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`)
122+
#/
123+
$(c_targets): %.out: %.c
124+
$(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES)
125+
126+
#/
127+
# Runs compiled benchmarks.
128+
#
129+
# @example
130+
# make run
131+
#/
132+
run: $(c_targets)
133+
$(QUIET) ./$<
134+
135+
.PHONY: run
136+
137+
#/
138+
# Removes generated files.
139+
#
140+
# @example
141+
# make clean
142+
#/
143+
clean:
144+
$(QUIET) -rm -f *.o *.out
145+
146+
.PHONY: clean

0 commit comments

Comments
 (0)