Class DoubleToString

java.lang.Object
xal.tools.text.DoubleToString

public class DoubleToString extends Object
This algorithm for appending doubles to StringBuffer is borrowed from "Java Performance Tuning" by Jack Shirazi. He explains how the JDK implementation is "hideously under-optimized". This implementation is considerably more efficient both in terms of speed and memory usage.
Author:
Craig McChesney
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final char[]
    Character array representing number infinity
    static final char[]
    Character array representing Not-A-Number
    static final char[][]
    Ordered vectors of zeros
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    append(StringBuffer s, double d)
    I think this is one of the two main methods in this class.
    static void
    append(StringBuffer s, int i)
    I think this is one of the two main methods in this class.
    static void
    appendAsDouble(StringBuffer s, long l, long lMag, int dMagnitude, int numFractDigits, char decimalPoint, char thousandsSeparator, int numDigitsSeparated, char negativePrefix, char negativeSuffix)
    One again, I'm not sure how to use this method, Craig was the original author.
    static void
    appendFormatted(StringBuffer s, double d, int numFractDigits, char decimalPoint, char thousandsSeparator, int numDigitsSeparated, char negativePrefix, char negativeSuffix)
    I'm not sure how this works or what it does since Craig originally build this class.
    static long
    getNthDigit(long l, int n)
     
    static void
    main(String[] args)
     
    static void
    main1(String[] args)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • INFINITY

      public static final char[] INFINITY
      Character array representing number infinity
    • NaN

      public static final char[] NaN
      Character array representing Not-A-Number
    • ZEROS

      public static final char[][] ZEROS
      Ordered vectors of zeros
  • Constructor Details

    • DoubleToString

      public DoubleToString()
  • Method Details

    • appendFormatted

      public static void appendFormatted(StringBuffer s, double d, int numFractDigits, char decimalPoint, char thousandsSeparator, int numDigitsSeparated, char negativePrefix, char negativeSuffix)
      I'm not sure how this works or what it does since Craig originally build this class. There's not much documentation.
      Parameters:
      s -
      d -
      numFractDigits -
      decimalPoint -
      thousandsSeparator -
      numDigitsSeparated -
      negativePrefix -
      negativeSuffix -
      Since:
      Apr 19, 2011
    • appendAsDouble

      public static void appendAsDouble(StringBuffer s, long l, long lMag, int dMagnitude, int numFractDigits, char decimalPoint, char thousandsSeparator, int numDigitsSeparated, char negativePrefix, char negativeSuffix)
      One again, I'm not sure how to use this method, Craig was the original author.
      Parameters:
      s -
      l -
      lMag -
      dMagnitude -
      numFractDigits -
      decimalPoint -
      thousandsSeparator -
      numDigitsSeparated -
      negativePrefix -
      negativeSuffix -
      Since:
      Apr 19, 2011
    • getNthDigit

      public static long getNthDigit(long l, int n)
    • main

      public static void main(String[] args)
    • main1

      public static void main1(String[] args)
    • append

      public static void append(StringBuffer s, double d)
      I think this is one of the two main methods in this class. It appends a double number to a StringBuffer object using optimized float-to-character representation algorithms.
      Parameters:
      s - string buffer
      d - a double-valued number being appended to the string
      Since:
      Apr 19, 2011
    • append

      public static void append(StringBuffer s, int i)
      I think this is one of the two main methods in this class. It appends an integer number to a StringBuffer object using optimized float-to-character representation algorithms.
      Parameters:
      s - string buffer
      i - a double-valued number being appended to the string
      Since:
      Apr 19, 2011