Java Number Compare getDifficulty(long compactTarget)

Here you can find the source of getDifficulty(long compactTarget)

Description

Returns PoW difficulty (bdiff) for the target specified in a compact form known as "bits" in Bitcoin Core.

License

Open Source License

Declaration

public static BigDecimal getDifficulty(long compactTarget) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.math.BigDecimal;

public class Main {
    /**//from w w w.  j  av  a  2  s  .co  m
     * Returns PoW difficulty (bdiff) for the target specified in a compact form known as "bits" in Bitcoin Core.
     */
    public static BigDecimal getDifficulty(long compactTarget) {
        // TODO: this is about three orders of magnitude away from overflowing
        // TODO: optimize, see https://en.bitcoin.it/wiki/Difficulty
        double maxbody = Math.log(0x00ffff);
        double scaland = Math.log(256);
        double diff = Math.exp(maxbody - Math.log(compactTarget & 0x00ffffff)
                + scaland * (0x1d - ((compactTarget & 0xff000000) >> 24)));
        return BigDecimal.valueOf(diff);
    }
}

Related

  1. compareTo(Object value1, Object value2)
  2. compareTwoObject(Object o1, Object o2)
  3. compareValue(Object left, Object right)
  4. compareValues(String value, String type, Object obj)
  5. getCrosstabRowColumnValue(String groupIdentifier, Map crosstabInfoMap, Object executorUnitId, String financesBankId, String companyNumber, String accountNumber)
  6. toPrimaryValue(Comparable comp)