PageRenderTime 142ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://github.com/tisoft/xmlvm
Java | 86 lines | 57 code | 4 blank | 25 comment | 6 complexity | d00cf751ea3ce9347c3ae76d53a07a44 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 java.lang.Float
  23. */
  24. public class FloatTest {
  25. public static void main(String[] args) {
  26. int numTests = 14;
  27. String[] description = new String[numTests];
  28. boolean[] result = new boolean[numTests];
  29. int i = -1;
  30. // floatToIntBits:
  31. i++;
  32. result[i] = Float.floatToIntBits(Float.NaN) == 0x7FC00000;
  33. description[i] = "floatToIntBits(NaN) == 0x7FC00000";
  34. i++;
  35. result[i] = Float.floatToIntBits(Float.POSITIVE_INFINITY) == 0x7F800000;
  36. description[i] = "floatToIntBits(+Infinity) == 0x7F800000";
  37. i++;
  38. result[i] = Float.floatToIntBits(Float.NEGATIVE_INFINITY) == 0xFF800000;
  39. description[i] = "floatToIntBits(-Infinity) == 0x0xFF800000";
  40. i++;
  41. result[i] = Float.compare(Float.intBitsToFloat(Float.floatToIntBits(1.546F)),1.546F)==0;
  42. description[i] = "longBitsToFloat(floatToIntBits(x))==x, for some x";
  43. i++;
  44. result[i] = Float.floatToIntBits(-1.461381E-12F) == 0xABCDABCD;
  45. description[i] = "floatToIntBits(-1.461381E-12) == 0xABCDABCD";
  46. // intBitsToFloat:
  47. i++;
  48. result[i] = Float.compare(Float.intBitsToFloat(0x7F800000),
  49. Float.POSITIVE_INFINITY)==0;
  50. description[i] = "intBitsToFloat(0x7F800000)==+Infinity";
  51. i++;
  52. result[i] = Float.compare(Float.intBitsToFloat(0xFF800000),
  53. Float.NEGATIVE_INFINITY)==0;
  54. description[i] = "intBitsToFloat(0xFF800000)==-Infinity";
  55. i++;
  56. result[i] = Float.isNaN(Float.intBitsToFloat(0x7F800001));
  57. description[i] = "intBitsToFloat(0x7F800001)==NaN";
  58. i++;
  59. result[i] = Float.isNaN(Float.intBitsToFloat(0x7FABCDEF));
  60. description[i] = "intBitsToFloat(0x7FABCDEF)==NaN";
  61. i++;
  62. result[i] = Float.isNaN(Float.intBitsToFloat(0x7FFFFFFF));
  63. description[i] = "intBitsToFloat(0x7FFFFFFF)==NaN";
  64. i++;
  65. result[i] = Float.isNaN(Float.intBitsToFloat(0xFF800001));
  66. description[i] = "intBitsToFloat(0xFF800001)==NaN";
  67. i++;
  68. result[i] = Float.isNaN(Float.intBitsToFloat(0xFFABCDEF));
  69. description[i] = "intBitsToFloat(0xFFABCDEF)==NaN";
  70. i++;
  71. result[i] = Float.isNaN(Float.intBitsToFloat(0xFFFFFFFF));
  72. description[i] = "intBitsToFloat(0xFFFFFFFF)==NaN";
  73. i++;
  74. result[i] = Float.compare(Float.intBitsToFloat(0x12341234), 5.682042E-28F) == 0;
  75. description[i] = "intBitsToFloat(0x12341234)==5.682042E-28";
  76. // print results
  77. for (int j=0; j<numTests; j++) {
  78. System.out.println(j + ") "
  79. + (result[j] ? "passed" : "failed") + ": "+ description[j]);
  80. }
  81. }
  82. }