alloy-rs / alloy-rs/ruint

`pow`: Round negative to zero.

Open
#100 0 comments 0 reactions 1 assignee Claimed by @recmo View on GitHub
feature tracker
Dominant language
Rust
Stars
225
Forks
70
Avg merge
16h 54m
Merged PRs (30d)
8

Description

*On 2022-05-31 @recmo wrote in [`c1a0c34`](https://github.com/recmo/uint/commit/c1a0c34df8ab6d3411ad79c27b72ad812eff78e4) “Merge pull request #97 from recmo/isqrt”:*

Round negative to zero.
Self::BITS ~< 2^52 and so fits f64.

```rust
#[must_use]
pub fn approx_pow2(exp: f64) -> Option {
const LN2_1P5: f64 = 0.584_962_500_721_156_2_f64;
const EXP2_63: f64 = 9_223_372_036_854_775_808_f64;

// FEATURE: Round negative to zero.
#[allow(clippy::cast_precision_loss)] // Self::BITS ~< 2^52 and so fits f64.
if exp < LN2_1P5 {
if exp < -1.0 {
return Some(Self::ZERO);
}
return Self::try_from(1).ok();

```
*From [`src/pow.rs:101`](https://github.com/recmo/uint/blob/c1a0c34df8ab6d3411ad79c27b72ad812eff78e4/src/pow.rs#L101)*

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.