Revision: 5601 http://jnode.svn.sourceforge.net/jnode/?rev=5601&view=rev Author: lsantha Date: 2009-07-11 15:53:36 +0000 (Sat, 11 Jul 2009)
Log Message: ----------- Fixed ldiv and lrem for Long.MIN_VALUE and Long.MAX_VALUE. Modified Paths: -------------- trunk/core/src/core/org/jnode/vm/MathSupport.java Modified: trunk/core/src/core/org/jnode/vm/MathSupport.java =================================================================== --- trunk/core/src/core/org/jnode/vm/MathSupport.java 2009-07-11 15:43:24 UTC (rev 5600) +++ trunk/core/src/core/org/jnode/vm/MathSupport.java 2009-07-11 15:53:36 UTC (rev 5601) @@ -17,7 +17,7 @@ * along with this library; If not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ - + package org.jnode.vm; import org.jnode.annotation.MagicPermission; @@ -39,6 +39,24 @@ * New Implementation */ public static long ldiv(long num, long den) { + if (num == Long.MIN_VALUE) { + if (den == Long.MIN_VALUE) { + return 1; + } else { + long q = ldiv(num + 1, den); + long r = num + 1 - q * den; + if (Math.abs(r) == Math.abs(den) - 1) { + return q < 0 ? q - 1 : q + 1; + } else { + return q; + } + } + } + + if(den == Long.MIN_VALUE) { + return 0; + } + boolean neg = false; if (num < 0) { num = -num; @@ -74,11 +92,27 @@ return -result; return result; } - /** * new implementation */ public static long lrem(long num, long den) { + if (num == Long.MIN_VALUE) { + if (den == Long.MIN_VALUE) { + return 0; + } else { + long r = lrem(num + 1, den); + if (Math.abs(r) == Math.abs(den) - 1) { + return 0; + } else { + return r < 0 ? r - 1 : r > 0 ? r + 1 : -1; + } + } + } + + if(den == Long.MIN_VALUE) { + return num; + } + final boolean neg; if (num < 0) { num = -num; @@ -113,7 +147,6 @@ return -num; return num; } - /* private final char[] v = new char[5]; private final char[] u = new char[5]; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Enter the BlackBerry Developer Challenge This is your chance to win up to $100,000 in prizes! For a limited time, vendors submitting new applications to BlackBerry App World(TM) will have the opportunity to enter the BlackBerry Developer Challenge. See full prize details at: http://p.sf.net/sfu/Challenge _______________________________________________ Jnode-svn-commits mailing list Jnode-svn-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jnode-svn-commits