summaryrefslogtreecommitdiffstats
path: root/test/422-type-conversion
diff options
context:
space:
mode:
authorRoland Levillain <rpl@google.com>2014-12-03 16:04:28 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2014-12-03 16:04:28 +0000
commit9a64a46e8edfa89402598d8650b8ebb337ba3d52 (patch)
tree78b29260bf542f7a21ed072425aa125a2ccffbf8 /test/422-type-conversion
parentadd2f944284992106cd9a1f1df93a17d666eaaf6 (diff)
parent3f8f936aff35f29d86183d31c20597ea17e9789d (diff)
downloadart-9a64a46e8edfa89402598d8650b8ebb337ba3d52.zip
art-9a64a46e8edfa89402598d8650b8ebb337ba3d52.tar.gz
art-9a64a46e8edfa89402598d8650b8ebb337ba3d52.tar.bz2
Merge "Add support for float-to-int in the optimizing compiler."
Diffstat (limited to 'test/422-type-conversion')
-rw-r--r--test/422-type-conversion/src/Main.java32
1 files changed, 32 insertions, 0 deletions
diff --git a/test/422-type-conversion/src/Main.java b/test/422-type-conversion/src/Main.java
index c434db3..e7dbe24 100644
--- a/test/422-type-conversion/src/Main.java
+++ b/test/422-type-conversion/src/Main.java
@@ -91,6 +91,9 @@ public class Main {
// Generate, compile and check long-to-double Dex instructions.
longToDouble();
+ // Generate, compile and check float-to-int Dex instructions.
+ floatToInt();
+
// Generate, compile and check int-to-byte Dex instructions.
shortToByte();
intToByte();
@@ -313,6 +316,32 @@ public class Main {
assertDoubleEquals(-9223372036854775808D, $opt$LongToDouble(-9223372036854775808L)); // -(2^63)
}
+ private static void floatToInt() {
+ assertIntEquals(1, $opt$FloatToInt(1F));
+ assertIntEquals(0, $opt$FloatToInt(0F));
+ assertIntEquals(0, $opt$FloatToInt(-0F));
+ assertIntEquals(-1, $opt$FloatToInt(-1F));
+ assertIntEquals(51, $opt$FloatToInt(51F));
+ assertIntEquals(-51, $opt$FloatToInt(-51F));
+ assertIntEquals(0, $opt$FloatToInt(0.5F));
+ assertIntEquals(0, $opt$FloatToInt(0.4999999F));
+ assertIntEquals(0, $opt$FloatToInt(-0.4999999F));
+ assertIntEquals(0, $opt$FloatToInt(-0.5F));
+ assertIntEquals(42, $opt$FloatToInt(42.199F));
+ assertIntEquals(-42, $opt$FloatToInt(-42.199F));
+ assertIntEquals(2147483647, $opt$FloatToInt(2147483647F)); // 2^31 - 1
+ assertIntEquals(-2147483648, $opt$FloatToInt(-2147483647F)); // -(2^31 - 1)
+ assertIntEquals(-2147483648, $opt$FloatToInt(-2147483648F)); // -(2^31)
+ assertIntEquals(2147483647, $opt$FloatToInt(2147483648F)); // (2^31)
+ assertIntEquals(-2147483648, $opt$FloatToInt(-2147483649F)); // -(2^31 + 1)
+ assertIntEquals(2147483647, $opt$FloatToInt(9223372036854775807F)); // 2^63 - 1
+ assertIntEquals(-2147483648, $opt$FloatToInt(-9223372036854775807F)); // -(2^63 - 1)
+ assertIntEquals(-2147483648, $opt$FloatToInt(-9223372036854775808F)); // -(2^63)
+ assertIntEquals(0, $opt$FloatToInt(Float.NaN));
+ assertIntEquals(2147483647, $opt$FloatToInt(Float.POSITIVE_INFINITY));
+ assertIntEquals(-2147483648, $opt$FloatToInt(Float.NEGATIVE_INFINITY));
+ }
+
private static void shortToByte() {
assertByteEquals((byte)1, $opt$ShortToByte((short)1));
assertByteEquals((byte)0, $opt$ShortToByte((short)0));
@@ -468,6 +497,9 @@ public class Main {
// This method produces a long-to-double Dex instruction.
static double $opt$LongToDouble(long a){ return (double)a; }
+ // This method produces a float-to-int Dex instruction.
+ static int $opt$FloatToInt(float a){ return (int)a; }
+
// These methods produce int-to-byte Dex instructions.
static byte $opt$ShortToByte(short a){ return (byte)a; }
static byte $opt$IntToByte(int a){ return (byte)a; }