From b3850ac76db7897a86e5cbac29e72092c8cc75e5 Mon Sep 17 00:00:00 2001 From: Ben Limmer Date: Wed, 28 Dec 2011 15:52:53 -0700 Subject: [PATCH] Initial attempt at resolving SWT3.7 missing operatons in Avian. Everything seems to be working except floatToIntBits, hence the test case failing. --- classpath/java/io/File.java | 4 ++++ classpath/java/lang/Float.java | 17 +++++++++++++++-- classpath/java/net/URL.java | 18 ++++++++++++++++++ test/Floats.java | 27 +++++++++++++++++++++++++++ 4 files changed, 64 insertions(+), 2 deletions(-) diff --git a/classpath/java/io/File.java b/classpath/java/io/File.java index 51e006e53f..9342627bd5 100644 --- a/classpath/java/io/File.java +++ b/classpath/java/io/File.java @@ -61,6 +61,10 @@ public class File implements Serializable { return isFile(path); } + public boolean isAbsolute() { + return path.equals(toAbsolutePath(path)); + } + private static native boolean canRead(String path); public boolean canRead() { diff --git a/classpath/java/lang/Float.java b/classpath/java/lang/Float.java index 1e2c62972b..d466cca2a3 100644 --- a/classpath/java/lang/Float.java +++ b/classpath/java/lang/Float.java @@ -12,8 +12,10 @@ package java.lang; public final class Float extends Number { public static final Class TYPE = Class.forCanonicalName("F"); - - private final float value; + private static final int EXP_BIT_MASK = 0x7F800000; + private static final int SIGNIF_BIT_MASK = 0x007FFFFF; + + private final float value; public Float(String value) { this.value = parseFloat(value); @@ -88,6 +90,17 @@ public final class Float extends Number { throw new NumberFormatException(s); } } + + public static int floatToIntBits(float value) { + int result = floatToRawIntBits(value); + + // Check for NaN based on values of bit fields, maximum + // exponent and nonzero significand. + if (((result & EXP_BIT_MASK) == EXP_BIT_MASK) && (result & SIGNIF_BIT_MASK) != 0) { + result = 0x7fc00000; + } + return result; + } public static native int floatToRawIntBits(float value); diff --git a/classpath/java/net/URL.java b/classpath/java/net/URL.java index 874eec964b..eb46c61860 100644 --- a/classpath/java/net/URL.java +++ b/classpath/java/net/URL.java @@ -19,6 +19,8 @@ public final class URL { private String host; private int port; private String file; + private String path; + private String query; private String ref; public URL(String s) throws MalformedURLException { @@ -55,6 +57,14 @@ public final class URL { public String getRef() { return ref; } + + public String getPath() { + return path; + } + + public String getQuery() { + return query; + } public URLConnection openConnection() throws IOException { return handler.openConnection(this); @@ -90,5 +100,13 @@ public final class URL { this.port = port; this.file = file; this.ref = ref; + + int q = file.lastIndexOf('?'); + if (q != -1) { + this.query = file.substring(q + 1); + this.path = file.substring(0, q); + } else { + this.path = file; + } } } diff --git a/test/Floats.java b/test/Floats.java index 38ae3121b1..e27e703d40 100644 --- a/test/Floats.java +++ b/test/Floats.java @@ -211,5 +211,32 @@ public class Floats { double d = (double) z; expect(d == 12345.0); } + + { + int NaN = 0x7F800001; + int result = Float.floatToIntBits(NaN); + int expected = 0x7fc00000; + System.out.println("NaN integer is: " + result + " and we were expecting it to be: " + expected); + expect(result == expected); + } + + { + int number = 0x00800001; + int result = Float.floatToIntBits(number); + System.out.println("Number1 is: " + result); + + expect(result == number); + + + } + + { + int number = 0x80800003; + int result = Float.floatToIntBits(number); + System.out.println("Number2 is: " + result); + expect(result == number); + + + } } }