[GHC] #14818: Provide highestOneBit function in Data.Bits module

GHC ghc-devs at haskell.org
Sun Feb 18 03:45:28 UTC 2018


#14818: Provide highestOneBit function in Data.Bits module
-------------------------------------+-------------------------------------
           Reporter:  kostmo         |             Owner:  (none)
               Type:  feature        |            Status:  new
  request                            |
           Priority:  normal         |         Milestone:
          Component:                 |           Version:  8.2.2
  libraries/base                     |
           Keywords:                 |  Operating System:  Unknown/Multiple
       Architecture:                 |   Type of failure:  None/Unknown
  Unknown/Multiple                   |
          Test Case:                 |        Blocked By:
           Blocking:                 |   Related Tickets:
Differential Rev(s):                 |         Wiki Page:
-------------------------------------+-------------------------------------
 This function yields the [https://stackoverflow.com/a/17379704/105137
 largest power of 2 less than or equal to the given number].


 Relative 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].

 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).

-- 
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14818>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list