From a81b77a37e86e51cf0f976349b7dcadc3eb3c1fd Mon Sep 17 00:00:00 2001 From: Eric Scharff Date: Thu, 25 Oct 2007 14:26:51 -0600 Subject: [PATCH] fixes i2f i2d implementation. Fixes image drawing bugs on Mac OS X. Also fixes a crash caused by implementing StringBuffer.toString(float) --- classpath/java/lang/StringBuffer.java | 5 +++++ src/common.h | 4 ++-- src/interpret.cpp | 4 ++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/classpath/java/lang/StringBuffer.java b/classpath/java/lang/StringBuffer.java index 6bb212475d..d216370464 100644 --- a/classpath/java/lang/StringBuffer.java +++ b/classpath/java/lang/StringBuffer.java @@ -40,6 +40,11 @@ public class StringBuffer { return this; } + public synchronized StringBuffer append(float v) { + sb.append(v); + return this; + } + public synchronized StringBuffer append(char[] b, int offset, int length) { sb.append(b, offset, length); return this; diff --git a/src/common.h b/src/common.h index bc18082a26..625cf2c076 100644 --- a/src/common.h +++ b/src/common.h @@ -207,14 +207,14 @@ hash(const uint16_t* s, unsigned length) inline uint32_t floatToBits(float f) { - int32_t bits; memcpy(&bits, &f, 4); + uint32_t bits; memcpy(&bits, &f, 4); return bits; } inline uint64_t doubleToBits(double d) { - int64_t bits; memcpy(&bits, &d, 8); + uint64_t bits; memcpy(&bits, &d, 8); return bits; } diff --git a/src/interpret.cpp b/src/interpret.cpp index 4aa2b747e5..42b71684bd 100644 --- a/src/interpret.cpp +++ b/src/interpret.cpp @@ -1479,11 +1479,11 @@ interpret(Thread* t) } goto loop; case i2d: { - pushDouble(t, static_cast(popInt(t))); + pushDouble(t, static_cast(static_cast(popInt(t)))); } goto loop; case i2f: { - pushFloat(t, static_cast(popInt(t))); + pushFloat(t, static_cast(static_cast(popInt(t)))); } goto loop; case i2l: {