GHC issueshttps://gitlab.haskell.org/ghc/ghc/-/issues2019-07-07T18:15:27Zhttps://gitlab.haskell.org/ghc/ghc/-/issues/14818Provide highestOneBit function in Data.Bits module2019-07-07T18:15:27ZkostmoProvide highestOneBit function in Data.Bits moduleThis function yields the [largest power of 2 less than or equal to the given number](https://stackoverflow.com/a/17379704/105137).
Relative to the Java standard library, which [provides this function](https://docs.oracle.com/javase/7/do...This function yields the [largest power of 2 less than or equal to the given number](https://stackoverflow.com/a/17379704/105137).
Relative to the Java standard library, which [provides this function](https://docs.oracle.com/javase/7/docs/api/java/lang/Integer.html#highestOneBit(int)), there is a gap in the Haskell library, even though the Haskell docs [describe a method to calculate logBase2 via the \`countLeadingZeros\` function](https://hackage.haskell.org/package/base-4.10.1.0/docs/Data-Bits.html#v:countLeadingZeros).
From the Java documentation:
> The implementations of the "bit twiddling" methods (such as `highestOneBit` and `numberOfTrailingZeros`) are based on material from Henry S. Warren, Jr.'s ''Hacker's Delight'', (Addison Wesley, 2002).
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | -------------- |
| Version | 8.2.2 |
| Type | FeatureRequest |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | libraries/base |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"Provide highestOneBit function in Data.Bits module","status":"New","operating_system":"","component":"libraries/base","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.2.2","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"FeatureRequest","description":"This function yields the [https://stackoverflow.com/a/17379704/105137 largest power of 2 less than or equal to the given number].\r\n\r\n\r\nRelative to the Java standard library, which [https://docs.oracle.com/javase/7/docs/api/java/lang/Integer.html#highestOneBit(int) provides this function], there is a gap in the Haskell library, even though the Haskell docs [https://hackage.haskell.org/package/base-4.10.1.0/docs/Data-Bits.html#v:countLeadingZeros describe a method to calculate logBase2 via the `countLeadingZeros` function].\r\n\r\nFrom the Java documentation:\r\n\r\n> The implementations of the \"bit twiddling\" methods (such as `highestOneBit` and `numberOfTrailingZeros`) are based on material from Henry S. Warren, Jr.'s ''Hacker's Delight'', (Addison Wesley, 2002).","type_of_failure":"OtherFailure","blocking":[]} -->7.10.1