test/tools/javac/HexFloatLiterals.java

Print this page




   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  20  * CA 95054 USA or visit www.sun.com if you need additional information or
  21  * have any questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 4920023
  27  * @summary add "hexadecimal floating-point literal" support to javac as per 4896828
  28  * @author gafter
  29  *
  30  * @compile -source 1.5 HexFloatLiterals.java
  31  * @run main HexFloatLiterals
  32  */
  33 
  34 public class HexFloatLiterals {
  35     public static void check(float a, float b) {
  36         if (a != b) throw new Error(a + " != " + b);
  37     }
  38     public static void check(double a, double b) {
  39         if (a != b) throw new Error(a + " != " + b);
  40     }
  41     public static void main(String[] args) {
  42         check(-0X.003p12d, Double.parseDouble("-0X.003p12d"));
  43         check(-0x.003P12F, Float.parseFloat("-0x.003P12F"));
  44         check(0x.006p11D, Double.parseDouble("0x.006p11D"));
  45         check(0X.00cP10D, Double.parseDouble("0X.00cP10D"));
  46         check(-0x.018P9, Double.parseDouble("-0x.018P9"));
  47         check(0x.018P9D, Double.parseDouble("0x.018P9D"));
  48         check(0X.018P9D, Double.parseDouble("0X.018P9D"));
  49         check(-0x.3p4F, Float.parseFloat("-0x.3p4F"));
  50         check(0x.3p4d, Double.parseDouble("0x.3p4d"));
  51         check(+0x.Cp2F, Float.parseFloat("+0x.Cp2F"));




   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  20  * CA 95054 USA or visit www.sun.com if you need additional information or
  21  * have any questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 4920023
  27  * @summary add "hexadecimal floating-point literal" support to javac as per 4896828
  28  * @author gafter



  29  */
  30 
  31 public class HexFloatLiterals {
  32     public static void check(float a, float b) {
  33         if (a != b) throw new Error(a + " != " + b);
  34     }
  35     public static void check(double a, double b) {
  36         if (a != b) throw new Error(a + " != " + b);
  37     }
  38     public static void main(String[] args) {
  39         check(-0X.003p12d, Double.parseDouble("-0X.003p12d"));
  40         check(-0x.003P12F, Float.parseFloat("-0x.003P12F"));
  41         check(0x.006p11D, Double.parseDouble("0x.006p11D"));
  42         check(0X.00cP10D, Double.parseDouble("0X.00cP10D"));
  43         check(-0x.018P9, Double.parseDouble("-0x.018P9"));
  44         check(0x.018P9D, Double.parseDouble("0x.018P9D"));
  45         check(0X.018P9D, Double.parseDouble("0X.018P9D"));
  46         check(-0x.3p4F, Float.parseFloat("-0x.3p4F"));
  47         check(0x.3p4d, Double.parseDouble("0x.3p4d"));
  48         check(+0x.Cp2F, Float.parseFloat("+0x.Cp2F"));