Skip to content

fix: resolve miscellaneous errors in various C examples #1691

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 5, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "stdlib/math/base/special/ceiln.h"
#include <stdio.h>

int main() {
int main( void ) {
const double x[] = { 3.14, -3.14, 0.0, 0.0/0.0 };

double y;
Expand Down
6 changes: 3 additions & 3 deletions lib/node_modules/@stdlib/math/base/special/ceiln/src/ceiln.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
// VARIABLES //

static const double MAX_INT = STDLIB_CONSTANT_FLOAT64_MAX_SAFE_INTEGER + 1.0;
static const double HUGE = 1.0e+308;
static const double HUGE_VALUE = 1.0e+308;


// MAIN //
Expand Down Expand Up @@ -91,11 +91,11 @@ double stdlib_base_ceiln( const double x, const int32_t n ) {
// If we overflow, return `x`, as the number of digits to the right of the decimal is too small (i.e., `x` is too large / lacks sufficient fractional precision) for there to be any effect when rounding...
if ( n < STDLIB_CONSTANT_FLOAT64_MIN_BASE10_EXPONENT ) {
s = pow( 10.0, -( n + STDLIB_CONSTANT_FLOAT64_MAX_BASE10_EXPONENT ) ); // TODO: replace use of `pow` once have stdlib equivalent
y = ( x * HUGE ) * s; // order of operation matters!
y = ( x * HUGE_VALUE ) * s; // order of operation matters!
if ( stdlib_base_is_infinite( y ) ) {
return x;
}
return ( stdlib_base_ceil( y ) / HUGE ) / s;
return ( stdlib_base_ceil( y ) / HUGE_VALUE ) / s;
}
s = pow( 10.0, -n ); // TODO: replace use of `pow` once have stdlib equivalent
y = x * s;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "stdlib/math/base/special/floorn.h"
#include <stdio.h>

int main() {
int main( void ) {
const double x[] = { 3.14, -3.14, 0.0, 0.0/0.0 };

double y;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
// VARIABLES //

static const double MAX_INT = STDLIB_CONSTANT_FLOAT64_MAX_SAFE_INTEGER + 1.0;
static const double HUGE = 1.0e+308;
static const double HUGE_VALUE = 1.0e+308;


// MAIN //
Expand Down Expand Up @@ -134,11 +134,11 @@ double stdlib_base_floorn( const double x, const int32_t n ) {
// If we overflow, return `x`, as the number of digits to the right of the decimal is too small (i.e., `x` is too large / lacks sufficient fractional precision) for there to be any effect when rounding...
if ( n < STDLIB_CONSTANT_FLOAT64_MIN_BASE10_EXPONENT ) {
s = pow( 10.0, - ( n + STDLIB_CONSTANT_FLOAT64_MAX_BASE10_EXPONENT ) ); // TODO: replace use of `pow` once have stdlib equivalent
y = ( x * HUGE ) * s; // order of operation matters!
y = ( x * HUGE_VALUE ) * s; // order of operation matters!
if ( stdlib_base_is_infinite( y ) ) {
return x;
}
return ( stdlib_base_floor( y ) / HUGE ) / s;
return ( stdlib_base_floor( y ) / HUGE_VALUE ) / s;
}
s = pow( 10.0, -n ); // TODO: replace use of `pow` once have stdlib equivalent
y = x * s;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/

#include "stdlib/math/base/special/min.h"
#include <stdlib.h>
#include <stdio.h>

int main( void ) {
Expand All @@ -31,4 +32,4 @@ int main( void ) {
v = stdlib_base_min( x, y );
printf( "x: %lf, y: %lf, min(x, y): %lf\n", x, y, v );
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/

#include "stdlib/math/base/special/minabs.h"
#include <stdlib.h>
#include <stdio.h>

int main( void ) {
Expand All @@ -31,4 +32,4 @@ int main( void ) {
v = stdlib_base_minabs( x, y );
printf( "x: %lf, y: %lf, minabs(x, y): %lf\n", x, y, v );
}
}
}