11/**
22* @license Apache-2.0
33*
4- * Copyright (c) 2018 The Stdlib Authors.
4+ * Copyright (c) 2023 The Stdlib Authors.
55*
66* Licensed under the Apache License, Version 2.0 (the "License");
77* you may not use this file except in compliance with the License.
1616* limitations under the License.
1717*/
1818
19+ #include "stdlib/math/base/special/ccis.h"
20+ #include "stdlib/complex/float64/ctor.h"
21+ #include "stdlib/complex/float64/reim.h"
1922#include <stdlib.h>
2023#include <stdio.h>
2124#include <math.h>
22- #include <complex .h>
25+ #include <time .h>
2326#include <sys/time.h>
2427
25- #define NAME "cis"
28+ /**
29+ * Constants
30+ */
31+ #define NAME "ccis"
2632#define ITERATIONS 1000000
2733#define REPEATS 3
2834
35+ #define RAND_MIN -500.0
36+ #define RAND_MAX 500.0
37+ #define RAND_RANGE (RAND_MAX - RAND_MIN)
38+
2939/**
3040* Prints the TAP version.
3141*/
@@ -70,17 +80,17 @@ static void print_results( double elapsed ) {
7080static double tic ( void ) {
7181 struct timeval now ;
7282 gettimeofday ( & now , NULL );
73- return (double )now .tv_sec + (double )now .tv_usec / 1.0e6 ;
83+ return (double )now .tv_sec + (double )now .tv_usec / 1.0e6 ;
7484}
7585
7686/**
77- * Generates a random number on the interval [0,1 ).
87+ * Generates a random number on the interval [RAND_MIN, RAND_MAX ).
7888*
7989* @return random number
8090*/
8191static double rand_double ( void ) {
8292 int r = rand ();
83- return (double )r / ( (double )RAND_MAX + 1.0 );
93+ return ( RAND_RANGE * ( ( double )r / ( (double )RAND_MAX + 1.0 ) ) ) + RAND_MIN ;
8494}
8595
8696/**
@@ -95,23 +105,32 @@ static double benchmark( void ) {
95105 double t ;
96106 int i ;
97107
98- double complex z ;
108+ stdlib_complex128_t z1 ;
109+ stdlib_complex128_t z2 ;
99110
100111 t = tic ();
112+
101113 for ( i = 0 ; i < ITERATIONS ; i ++ ) {
102- re = ( 100.0 * rand_double () ) - 50.0 ;
103- im = ( 100.0 * rand_double () ) - 50.0 ;
114+ // Generate random real and imaginary parts for each iteration:
115+ re = rand_double ();
116+ im = rand_double ();
117+ z1 = stdlib_complex128 ( re , im );
104118
105- z = ( cos ( re ) + I * sin ( re ) ) / exp ( im );
106- if ( z != z ) {
107- printf ( "should not return NaN\n" );
119+ z2 = stdlib_base_ccis ( z1 );
120+ stdlib_complex128_reim ( z2 , & re , & im );
121+
122+ if ( isnan ( re ) ) {
123+ printf ( "should not return NaN for real part\n" );
124+ break ;
125+ }
126+ if ( isnan ( im ) ) {
127+ printf ( "should not return NaN for imaginary part\n" );
108128 break ;
109129 }
110130 }
131+
111132 elapsed = tic () - t ;
112- if ( z != z ) {
113- printf ( "should not return NaN\n" );
114- }
133+
115134 return elapsed ;
116135}
117136
@@ -126,11 +145,15 @@ int main( void ) {
126145 srand ( time ( NULL ) );
127146
128147 print_version ();
148+
129149 for ( i = 0 ; i < REPEATS ; i ++ ) {
130- printf ( "# c::%s\n" , NAME );
150+ printf ( "# c::native:: %s\n" , NAME );
131151 elapsed = benchmark ();
132152 print_results ( elapsed );
133- printf ( "ok %d benchmark finished\n" , i + 1 );
153+ printf ( "ok %d benchmark finished\n" , i + 1 );
134154 }
155+
135156 print_summary ( REPEATS , REPEATS );
157+
158+ return 0 ;
136159}
0 commit comments