VMDouble.java 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /* VMDouble.java -- VM Specific Double methods
  2. Copyright (C) 2003, 2005, 2006 Free Software Foundation
  3. This file is part of GNU Classpath.
  4. GNU Classpath is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. GNU Classpath is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Classpath; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  15. 02110-1301 USA.
  16. Linking this library statically or dynamically with other modules is
  17. making a combined work based on this library. Thus, the terms and
  18. conditions of the GNU General Public License cover the whole
  19. combination.
  20. As a special exception, the copyright holders of this library give you
  21. permission to link this library with independent modules to produce an
  22. executable, regardless of the license terms of these independent
  23. modules, and to copy and distribute the resulting executable under
  24. terms of your choice, provided that you also meet, for each linked
  25. independent module, the terms and conditions of the license of that
  26. module. An independent module is a module which is not derived from
  27. or based on this library. If you modify this library, you may extend
  28. this exception to your version of the library, but you are not
  29. obligated to do so. If you do not wish to do so, delete this
  30. exception statement from your version. */
  31. package java.lang;
  32. import gnu.classpath.Configuration;
  33. /*
  34. * This class is a reference version, mainly for compiling a class library
  35. * jar. It is likely that VM implementers replace this with their own
  36. * version that can communicate effectively with the VM.
  37. */
  38. /**
  39. * Code relocated from java.lang.Double by
  40. * @author Dave Grove (groved@us.ibm.com)
  41. */
  42. final class VMDouble
  43. {
  44. /**
  45. * Convert the double to the IEEE 754 floating-point "double format" bit
  46. * layout. Bit 63 (the most significant) is the sign bit, bits 62-52
  47. * (masked by 0x7ff0000000000000L) represent the exponent, and bits 51-0
  48. * (masked by 0x000fffffffffffffL) are the mantissa. This function
  49. * collapses all versions of NaN to 0x7ff8000000000000L. The result of this
  50. * function can be used as the argument to
  51. * <code>Double.longBitsToDouble(long)</code> to obtain the original
  52. * <code>double</code> value.
  53. *
  54. * @param value the <code>double</code> to convert
  55. * @return the bits of the <code>double</code>
  56. * @see #longBitsToDouble(long)
  57. */
  58. public static native long doubleToLongBits(double value);
  59. /**
  60. * Convert the double to the IEEE 754 floating-point "double format" bit
  61. * layout. Bit 63 (the most significant) is the sign bit, bits 62-52
  62. * (masked by 0x7ff0000000000000L) represent the exponent, and bits 51-0
  63. * (masked by 0x000fffffffffffffL) are the mantissa. This function
  64. * leaves NaN alone, rather than collapsing to a canonical value. The
  65. * result of this function can be used as the argument to
  66. * <code>Double.longBitsToDouble(long)</code> to obtain the original
  67. * <code>double</code> value.
  68. *
  69. * @param value the <code>double</code> to convert
  70. * @return the bits of the <code>double</code>
  71. * @see #longBitsToDouble(long)
  72. */
  73. public static native long doubleToRawLongBits(double value);
  74. /**
  75. * Convert the argument in IEEE 754 floating-point "double format" bit
  76. * layout to the corresponding float. Bit 63 (the most significant) is the
  77. * sign bit, bits 62-52 (masked by 0x7ff0000000000000L) represent the
  78. * exponent, and bits 51-0 (masked by 0x000fffffffffffffL) are the mantissa.
  79. * This function leaves NaN alone, so that you can recover the bit pattern
  80. * with <code>Double.doubleToRawLongBits(double)</code>.
  81. *
  82. * @param bits the bits to convert
  83. * @return the <code>double</code> represented by the bits
  84. * @see #doubleToLongBits(double)
  85. * @see #doubleToRawLongBits(double)
  86. */
  87. public static native double longBitsToDouble(long bits);
  88. /**
  89. * Helper method to convert to string.
  90. *
  91. * @param d the double to convert
  92. * @param isFloat true if the conversion is requested by Float (results in
  93. * fewer digits)
  94. */
  95. public static native String toString(double d, boolean isFloat);
  96. public static native double parseDouble(String str);
  97. }