package com.ripple.core.coretypes;

import com.ripple.core.coretypes.hash.Hash256;

import java.math.BigDecimal;
import java.math.BigInteger;

public class Quality  {
    public static BigDecimal fromBookDirectory(Hash256 bookDirectory, boolean payIsNative, boolean getIsNative) {
        byte[] value  = bookDirectory.slice(-7);
        int offset = bookDirectory.get(-8) - 100;
        return new BigDecimal(new BigInteger(1, value), -( payIsNative ? offset - 6 :
                                                           getIsNative ? offset + 6 :
                                                           offset ));
    }
}

@@ -168,187 +168,538 @@
     
-public static BigDecimal fromBookDirectory(Hash256 bookDirectory, boolean payIsNative, boolean getIsNative) %7B%0A        byte%5B%5D value  = bookDirectory.slice(-7);%0A        int offse
+/**%0A     * Finds the quality (TakerPays/TakerGets) ratio packed into the last 64%0A     * bits of root DirectoryNode ledger indexes.%0A     */%0A    public static BigDecimal fromBookDirectory(Hash256 bookDirectory,%0A                                               boolean payIsNative,%0A                                               boolean getIsNative) %7B%0A        // The last 7 bytes contains the mantissa%0A        byte%5B%5D mantissa  = bookDirectory.slice(-7);%0A        // Most significant byte has the exponent packed%0A        int exponen
 t =
+ (
  boo
@@ -716,16 +716,24 @@
 .get(-8)
+ & 0xFF)
  - 100;%0A
@@ -744,59 +744,94 @@
     
-r
+// R
 eturn 
-new BigDecimal(new BigInteger(1, value),
+the value in XRP scale, rather than drops, as stored.%0A        int scale =
  -(
- 
 payI
@@ -840,21 +840,23 @@
 ative ? 
-offse
+exponen
 t - 6 :%0A
@@ -881,139 +881,158 @@
     
-                   
-                  getIsNative ? offset + 6 :%0A                                                           offset )
+getIsNative ? exponent + 6 : exponent);%0A        BigInteger unsignedBig = new BigInteger(1, mantissa);%0A        return new BigDecimal(unsignedBig, scale
 );%0A 

Add comments to Quality.fromBookDirectory