This adds division and power implementations to UInt. Modulo and
division are handled by the same function. These are necessary for some
higher order mathematics, often involving large floating point numbers.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
libc/src/__support/CPP/UInt.h | ||
---|---|---|
41 ↗ | (On Diff #453822) | Not sure if there is a need to initialize from a bigger array. If not, can we restrict this constructor with enable_if? |
42 ↗ | (On Diff #453822) | Is the ternary operation correct? |
81 ↗ | (On Diff #453822) | Instead of a static_assert, can we use enable_if to restrict this overload? |
279 ↗ | (On Diff #453822) | cpp::optional? |
283 ↗ | (On Diff #453822) | Naming style. |
286–287 ↗ | (On Diff #453822) | This expression is a bit complicated to parse. Can you put it in a lambda function? |
Address comments and add mod and exp functions. Still need to add tests for those last two.
libc/src/__support/CPP/UInt.h | ||
---|---|---|
41 ↗ | (On Diff #453822) | Re: sivachandra, we can't use enable_if here because typetraits.h depends on UInt.h. |
42 ↗ | (On Diff #453822) | oops, flipped. |
81 ↗ | (On Diff #453822) | No. TypeTraits depends on UInt, so UInt can't use anything from TypeTraits. This includes enable_if. |
libc/src/__support/CPP/UInt.h | ||
---|---|---|
236 ↗ | (On Diff #454620) | What is the use case of detecting the overflow? |
293 ↗ | (On Diff #454620) | Should we implement operator==(uint64_t) to make this cleaner like: other == uint64_t(1)? |
297 ↗ | (On Diff #454620) | You should be able to do return cpp::nullopt; |
338 ↗ | (On Diff #454620) | |
libc/test/src/__support/uint128_test.cpp | ||
160 | We should include them in this patch? Also, if multiplication overflow is required, we should test for that also? |
libc/src/__support/CPP/UInt.h | ||
---|---|---|
41 ↗ | (On Diff #453822) | Considering that we are moving to make the CPP directory a strict subset of the C++ standard library, we should move the is_integral specialization for UInt to this file or may be to UInt128.h. |
libc/src/__support/CPP/UInt.h | ||
---|---|---|
236 ↗ | (On Diff #454620) | I used it in my initial division implementation, but I don't have a use for it now, so I've removed it. |
293 ↗ | (On Diff #454620) | It appears that's unnecessary. I just assumed it'd need the explicit typing, but it will apparently get promoted implicitly just fine. |
338 ↗ | (On Diff #454620) | that's in FPUtil, which depends on UInt. I will move that out in a followup patch, since it doesn't need to be in FPUtil. |
libc/src/__support/UInt.h | ||
---|---|---|
252 | I think the conventional name for this function is pown or pow_n. exp name is kind of reserved for e^x function. | |
261 | Can this be replaced with cur_power *= cur_power? | |
320–325 | Since you already included builtin_wrappers.h here, this part can be reduced to leading_zeroes += fputil::unsafe_clz(val[i-1]); |
I think the conventional name for this function is pown or pow_n. exp name is kind of reserved for e^x function.