Skip to content

Commit

Permalink
Add floorf() function to include/math.h
Browse files Browse the repository at this point in the history
  • Loading branch information
maximecb committed Sep 30, 2023
1 parent c96bac5 commit a936512
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
10 changes: 10 additions & 0 deletions ncc/include/math.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,14 @@
#define atanf(__f) (asm (__f) -> float { atans_f32; })
#define sqrtf(__f) (asm (__f) -> float { sqrt_f32; })

float floorf(float x)
{
float xi = (float)(int)x;

if (x < xi)
return xi - 1.0f;

return xi;
}

#endif
3 changes: 3 additions & 0 deletions ncc/tests/floats.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,8 @@ int main()
assert(sqrtf(4.0f) == 2.0f);
assert(sinf(0.0f) == 0.0f);

assert(floorf(4.5f) == 4.0f);
assert(floorf(-4.5f) == -5.0f);

return 0;
}

0 comments on commit a936512

Please sign in to comment.