Skip to content

Added log pow and fixed exp - #349

Merged
morousg merged 3 commits into
mainfrom
348-add-pow-and-powf-along-with-dependencies-in-cxp
Aug 19, 2026
Merged

Added log pow and fixed exp#349
morousg merged 3 commits into
mainfrom
348-add-pow-and-powf-along-with-dependencies-in-cxp

Conversation

@morousg

@morousg morousg commented Aug 19, 2026

Copy link
Copy Markdown
Member

No description provided.

@morousg
morousg requested a lite review from Copilot August 19, 2026 20:30
@morousg morousg self-assigned this Aug 19, 2026
@morousg morousg linked an issue Aug 19, 2026 that may be closed by this pull request

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR extends the cxp:: constexpr math utilities by adding log/pow support and adjusting the exp implementation, with accompanying unit tests to validate runtime vs constexpr behavior.

Changes:

  • Added new cxp::log / cxp::logf and cxp::pow / cxp::powf APIs in constexpr_cmath.h.
  • Refactored exp into a templated cxp::exp plus a float wrapper cxp::expf, and adjusted numeric-limits handling for CUDA builds.
  • Expanded utests to include sweeps/edge cases for expf, and compile-time + runtime tests for log and pow.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
include/fused_kernel/core/constexpr_libs/constexpr_cmath.h Adds log/pow, refactors exp, and adjusts CUDA numeric_limits plumbing.
utests/core/constexpr_libs/utest_constexpr_expf_exact.h Adds runtime/constexpr sweep checks for cxp::expf vs std::expf.
utests/core/constexpr_libs/utest_constexpr_cmath.h Adds compile-time and runtime validation for new log/pow APIs.
.github/copilot-instructions.md Documents guidance about not declaring CUDA compilation blocked based on ad hoc nvcc checks.
Suppressed comments (1)

include/fused_kernel/core/constexpr_libs/constexpr_cmath.h:1044

  • Same shadowing issue in powf::BaseFunc::exec: the parameter name base prevents base::is_constant_evaluated() from compiling. Rename the parameter and keep cxp::base namespace accesses unshadowed.
            using InstanceType = fk::BinaryType;
            FK_HOST_DEVICE_FUSE float exec(const float base, const float exponent) {
                if (base::is_constant_evaluated()) {
                    return pow::BaseFunc::exec(base, exponent);

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +948 to +952
using InstanceType = fk::BinaryType;
template <std::floating_point ST>
FK_HOST_DEVICE_FUSE ST exec(const ST base, const ST exponent) {
if (base::is_constant_evaluated()) {
return c_pow(base, exponent);
Copilot AI review requested due to automatic review settings August 19, 2026 20:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Suppressed comments (3)

include/fused_kernel/core/constexpr_libs/constexpr_cmath.h:954

  • pow::BaseFunc::exec names its first parameter base, which shadows the cxp::base namespace. As written, base::is_constant_evaluated() will not compile (attempts to use :: on a function parameter). Rename the parameter or fully-qualify the namespace (e.g. cxp::base::is_constant_evaluated()).
            FK_HOST_DEVICE_FUSE ST exec(const ST base, const ST exponent) {
                if (base::is_constant_evaluated()) {
                    return c_pow(base, exponent);
                } else {
                    return std::pow(base, exponent);

include/fused_kernel/core/constexpr_libs/constexpr_cmath.h:907

  • log::BaseFunc::c_log(double) similarly assumes a normal double when extracting exponent/mantissa. Subnormal doubles (exponent bits == 0, nonzero mantissa) will produce an incorrect result. Consider normalizing (e.g. scale by 2^54, adjust exponent) before computing e and m.
                    ulonglong bits = bit_cast<ulonglong>(x);
                    int e = static_cast<int>(bits >> 52) - 1023;
                    double m = bit_cast<double>((bits & 0x000FFFFFFFFFFFFFull) | 0x3FF0000000000000ull);

include/fused_kernel/core/constexpr_libs/constexpr_cmath.h:875

  • log::BaseFunc::c_log(float) extracts the exponent assuming a normal float. For subnormal inputs (exponent field == 0 but mantissa != 0), e/m are computed incorrectly, so constexpr cxp::log::f(x) will be wrong for subnormals. Add a normalization step similar to ldexpf (scale by 2^24, adjust exponent) before computing e and m.

This issue also appears on line 904 of the same file.

                    uint bits = bit_cast<uint>(x);
                    int e = static_cast<int>((bits >> 23) & 0xFF) - 127;

                    float m = bit_cast<float>((bits & 0x007FFFFF) | 0x3F800000);
                    if (m > 1.41421356237f) {

Comment on lines +1042 to +1046
FK_HOST_DEVICE_FUSE float exec(const float base, const float exponent) {
if (base::is_constant_evaluated()) {
return pow::BaseFunc::exec(base, exponent);
} else {
return std::pow(base, exponent);
Copilot AI review requested due to automatic review settings August 19, 2026 21:01
@morousg
morousg merged commit 5dc06d1 into main Aug 19, 2026
8 checks passed
@morousg
morousg deleted the 348-add-pow-and-powf-along-with-dependencies-in-cxp branch August 19, 2026 21:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

Comment on lines +783 to +786
if (x < -709.0)
return 0.0;
if (x > 709.0)
return base::numeric_limits<double>::infinity();
Comment on lines +871 to +874
uint bits = bit_cast<uint>(x);
int e = static_cast<int>((bits >> 23) & 0xFF) - 127;

float m = bit_cast<float>((bits & 0x007FFFFF) | 0x3F800000);
Comment on lines +982 to +991
if (base == 0.0f)
return (exponent > 0.0f) ? 0.0f : base::numeric_limits<float>::infinity();

if (base < 0.0f) {
int e_int = static_cast<int>(exponent);
if (static_cast<float>(e_int) == exponent) {
float res = exp::BaseFunc::exec(exponent * log::BaseFunc::exec(-base));
return (e_int % 2 != 0) ? -res : res;
}
return base::numeric_limits<float>::quiet_NaN();
#define CXP_F_FUNC \
template <typename... Types> \
FK_HOST_DEVICE_FUSE auto f(const Types... vals) { \
FK_HOST_DEVICE_FUSE decltype(auto) f(const Types... vals) { \
Comment on lines +730 to +731
template <std::floating_point ST>
FK_HOST_DEVICE_FUSE ST exec(const ST x) {
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.

Add pow and powf along with dependencies in cxp

2 participants