PageRenderTime 45ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/src/xmlvm2csharp/test/org/xmlvm/test/nativeImpl/DoubleTest.java

https://github.com/tisoft/xmlvm
Java | 94 lines | 63 code | 6 blank | 25 comment | 6 complexity | 66b994d476ca4e10890d63cc4b15055e MD5 | raw file
Possible License(s): LGPL-2.1
  1. /* Copyright (c) 2002-2011 by XMLVM.org
  2. *
  3. * Project Info: http://www.xmlvm.org
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU Lesser General Public License as published by
  7. * the Free Software Foundation; either version 2.1 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  12. * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
  13. * License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with this library; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
  18. * USA.
  19. */
  20. package org.xmlvm.test.nativeImpl;
  21. /*
  22. * tests native implementation of methods in java.lang.Double
  23. */
  24. public class DoubleTest {
  25. public static void main(String[] args) {
  26. int numTests = 16;
  27. String[] description = new String[numTests];
  28. boolean[] result = new boolean[numTests];
  29. int i = -1;
  30. // doubleToLongBits:
  31. i++;
  32. result[i] = Double.doubleToLongBits(Double.NaN) == 0x7FF8000000000000L;
  33. description[i] = "doubleToLongBits(NaN) == 0x7FF8000000000000L";
  34. i++;
  35. result[i] = Double.doubleToLongBits(Double.POSITIVE_INFINITY) == 0x7FF0000000000000L;
  36. description[i] = "doubleToLongBits(+Infinity) == 0x7FF0000000000000L";
  37. i++;
  38. result[i] = Double.doubleToLongBits(Double.NEGATIVE_INFINITY) == 0xFFF0000000000000L;
  39. description[i] = "doubleToLongBits(-Infinity) == 0xFFF0000000000000L";
  40. i++;
  41. result[i] = Double.compare(Double.longBitsToDouble(Double.doubleToLongBits(Math.PI/7)),Math.PI/7)==0;
  42. description[i] = "longBitsToDouble(doubleToLongBits(x))==x, for some x";
  43. i++;
  44. result[i] = Double.doubleToLongBits(Math.PI/7)==0x3FDCB91F3BBBA140L;
  45. description[i] = "doubleToLongBits(pi/7)==0x3FDCB91F3BBBA140";
  46. i++;
  47. result[i] = Double.doubleToLongBits(5.626349108908516E-221) == 0x1234567890ABCDEFL;
  48. description[i] = "doubleToLongBits(5.626349108908516E-221) == 0x1234567890ABCDEF";
  49. i++;
  50. result[i] = Double.doubleToLongBits(Math.sqrt(Math.E)) == 0x3FFA61298E1E069CL;
  51. description[i] = "doubleToLongBits(sqrt(e)) == 0x3FFA61298E1E069C";
  52. // longBitsToDouble:
  53. i++;
  54. result[i] = Double.compare(Double.longBitsToDouble(0x7FF0000000000000L),
  55. Double.POSITIVE_INFINITY)==0;
  56. description[i] = "longBitsToDouble(0x7FF0000000000000L)==+Infinity";
  57. i++;
  58. result[i] = Double.compare(Double.longBitsToDouble(0xFFF0000000000000L),
  59. Double.NEGATIVE_INFINITY)==0;
  60. description[i] = "longBitsToDouble(0xFFF0000000000000L)==-Infinity";
  61. i++;
  62. result[i] = Double.isNaN(Double.longBitsToDouble(0x7FF0000000000001L));
  63. description[i] = "longBitsToDouble(0x7FF0000000000001L)==NaN";
  64. i++;
  65. result[i] = Double.isNaN(Double.longBitsToDouble(0x7FF123456789ABCDL));
  66. description[i] = "longBitsToDouble(0x7FF123456789ABCDL)==NaN";
  67. i++;
  68. result[i] = Double.isNaN(Double.longBitsToDouble(0x7FFFFFFFFFFFFFFFL));
  69. description[i] = "longBitsToDouble(0x7FFFFFFFFFFFFFFFL)==NaN";
  70. i++;
  71. result[i] = Double.isNaN(Double.longBitsToDouble(0xFFF0000000000001L));
  72. description[i] = "longBitsToDouble(0xFFF0000000000001L)==NaN";
  73. i++;
  74. result[i] = Double.isNaN(Double.longBitsToDouble(0xFFF123456789ABCDL));
  75. description[i] = "longBitsToDouble(0xFFF123456789ABCDL)==NaN";
  76. i++;
  77. result[i] = Double.isNaN(Double.longBitsToDouble(0xFFFFFFFFFFFFFFFFL));
  78. description[i] = "longBitsToDouble(0xFFFFFFFFFFFFFFFFL)==NaN";
  79. i++;
  80. result[i] = Double.compare(Double.longBitsToDouble(0x13579BDF02468ACEL),1.7121363327076063E-215)==0;
  81. description[i] = "longBitsToDouble(0x13579BDF02468ACE)==1.7121363327076063E-215";
  82. // print results
  83. for (int j=0; j<numTests; j++) {
  84. System.out.println(j + ") "
  85. + (result[j] ? "passed" : "failed") + ": "+ description[j]);
  86. }
  87. }
  88. }