Skip to content

Commit

Permalink
docs: fix errors in various C examples
Browse files Browse the repository at this point in the history
PR-URL: 	#1691
Reviewed-by: Athan Reines <kgryte@gmail.com>
  • Loading branch information
Pranavchiku authored Mar 5, 2024
1 parent 16fda9a commit d829b75
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 10 deletions.
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 );
}
}
}

1 comment on commit d829b75

@stdlib-bot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage Report

Package Statements Branches Functions Lines
math/base/special/ceiln $\color{green}272/272$
$\color{green}+100.00\%$
$\color{green}24/24$
$\color{green}+100.00\%$
$\color{green}2/2$
$\color{green}+100.00\%$
$\color{green}272/272$
$\color{green}+100.00\%$
math/base/special/floorn $\color{green}272/272$
$\color{green}+100.00\%$
$\color{green}24/24$
$\color{green}+100.00\%$
$\color{green}2/2$
$\color{green}+100.00\%$
$\color{green}272/272$
$\color{green}+100.00\%$
math/base/special/min $\color{green}176/176$
$\color{green}+100.00\%$
$\color{green}16/16$
$\color{green}+100.00\%$
$\color{green}2/2$
$\color{green}+100.00\%$
$\color{green}176/176$
$\color{green}+100.00\%$
math/base/special/minabs $\color{green}160/160$
$\color{green}+100.00\%$
$\color{green}5/5$
$\color{green}+100.00\%$
$\color{green}2/2$
$\color{green}+100.00\%$
$\color{green}160/160$
$\color{green}+100.00\%$

The above coverage report was generated for the changes in this push.

Please sign in to comment.