Skip to content

Commit

Permalink
Update main.c
Browse files Browse the repository at this point in the history
Signed-off-by: Gunj Joshi <gunjjoshi8372@gmail.com>
  • Loading branch information
gunjjoshi committed Aug 20, 2024
1 parent 6818629 commit 984f378
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions lib/node_modules/@stdlib/math/base/special/wrap/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
#include "stdlib/math/base/special/wrap.h"
#include "stdlib/math/base/assert/is_nan.h"
#include "stdlib/math/base/special/trunc.h"
#include "stdlib/math/base/special/fmod.h"
#include "stdlib/math/base/special/abs.h"
#include <math.h>

// TODO: remove <math.h> header and fmod once we have stdlib equivalent

/**
* Wraps a value on the half-open interval [min,max).
Expand Down Expand Up @@ -48,13 +49,13 @@ double stdlib_base_wrap( const double v, const double min, const double max ) {
vc = v;

// Normalize +-0 to +0...
if ( stdlib_base_abs( vc ) == 0.0 ) {
if ( vc == 0.0 ) {
vc = 0.0;
}
if ( stdlib_base_abs( minc ) == 0.0 ) {
if ( minc == 0.0 ) {
minc = 0.0;
}
if ( stdlib_base_abs( maxc ) == 0.0 ) {
if ( maxc == 0.0 ) {
maxc = 0.0;
}
// Simple case where value is already within range...
Expand All @@ -66,5 +67,5 @@ double stdlib_base_wrap( const double v, const double min, const double max ) {
if ( vc < minc ) {
vc += delta * ( stdlib_base_trunc( ( minc - vc ) / delta ) + 1.0 );
}
return minc + ( stdlib_base_fmod( vc - minc, delta ) );
return minc + ( fmod( vc - minc, delta ) );
}

0 comments on commit 984f378

Please sign in to comment.