Skip to content

Add CLAMP Functions#86

Open
lukeqin-s wants to merge 6 commits intomainfrom
clamp_macro
Open

Add CLAMP Functions#86
lukeqin-s wants to merge 6 commits intomainfrom
clamp_macro

Conversation

@lukeqin-s
Copy link
Copy Markdown

Added a macro to clamp a value within specified bounds.

Added a macro to clamp a value within specified bounds.
@lukeqin-s lukeqin-s requested a review from celery6 March 30, 2026 22:32
@lukeqin-s lukeqin-s requested a review from JasonBrave as a code owner March 30, 2026 22:32
Copy link
Copy Markdown
Member

@JasonBrave JasonBrave left a comment

Choose a reason for hiding this comment

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

Also you need unit test, create a new file tests/test_math.cpp, add thorough test for each inline function, include corner cases. Add the test C++ file to Makefile at root

- Changed to static inline functions
- Added #include <stdint.h>
@lukeqin-s lukeqin-s changed the title Add CLAMP macro Add CLAMP Functions Mar 31, 2026
- Changed clamp function if statements to be expanded and more readable.
- Sorted TEST_SRCS by alphabetical order in Makefile
Copy link
Copy Markdown
Member

@JasonBrave JasonBrave left a comment

Choose a reason for hiding this comment

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

You need to add float32_t and float64_t 's typedef to common.h, make sure to add static assert to make sure they have corrent width

Then move the clamp functions to a new "mathops.h"

@lukeqin-s lukeqin-s force-pushed the clamp_macro branch 4 times, most recently from 03a297a to 221dfe1 Compare April 3, 2026 03:22
…t width checks.

Moved clamp functions to mathops.h.
Added mathops.h to Makefile.
Changed test_math.cpp to use float32_t.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants