Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@theraot
Copy link
Contributor

@theraot theraot commented Mar 4, 2014

Replaced the old convertion code with a direct cast to double and an indirect to float passing through double, also extended the tests for the cast. The new code will only read the most significant words of the BigInteger and therfore avoiding iterating over the whole value allowing for execution in near constant time [some cases take a short path].

Also added some new helper methods:

  • PopulationCount(ulong): returns the number of bits sets to 1 (new overload).
  • LeadingZeroCount(uint) & LeadingZeroCount(ulong): returns the number of bits set to 0 at the beginning.
  • BuildDouble: creates a new double by sign, mantissa and exponent.

theraot added 6 commits March 4, 2014 11:12
- The new helper method LeadingZeroCount returns the number of bits
  that are set to 0 at the start of an uint.
- The new implementation converts directly to double or float.
- Added overloads for PopulationCount and LeadingZeroCount that take ulong.
- Added helper method BuildDouble that constructs a double by sign, mantissa
  and exponent. This method truncates the mantissa, thus may differ in
  rounding to Math.Pow.
- The new implementation avoids Math.Pow by using BuildDouble.
- Passing all recently added tests.
- The new implementation casts to double and then to float.
marek-safar added a commit that referenced this pull request Mar 5, 2014
New cast to double and float for BigInteger
@marek-safar marek-safar merged commit 153692f into mono:master Mar 5, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants