xls icon indicating copy to clipboard operation
xls copied to clipboard

can't use std::upow in parametric expr

Open proppy opened this issue 1 year ago • 1 comments

trying to use std::upow in a parametric expr, like in the following example:

fn pow_param<N: u32, P: u32 = {std::upow(u32:2, N) - u32:1}>() -> uN[N] {
    P as uN[N]
}

result in the following error:

xls/dslx/stdlib/std.x:556:20-556:21
0554:         let result = if (n & uN[N]:1) == uN[N]:1 { result * p } else { result };
0555: 
0556:         (n >> 1, p * p, result)
~~~~~~~~~~~~~~~~~~~~~~~~~^ constexpr evaluation detected rollover in operation
0557:     }((n, p, result));
0558:     work.2

is that expected?

proppy avatar Feb 16 '24 23:02 proppy

What was the value used for N in the instantiation?

We maybe can/should make the error message better but it's trying to tell you that p * p rolled over in the u32 space which you may not have been expecting; i.e. p * p at infinite precision bits[∞] was not equal to the value when clamped to a bits[32].

cdleary avatar Feb 17 '24 19:02 cdleary

Closing as I don't think we have a reproducer.

cdleary avatar Apr 03 '24 20:04 cdleary