From 40338477e89ba8d10872fb95a3a54a375fa1f268 Mon Sep 17 00:00:00 2001
From: Colin Jones <trptcolin@gmail.com>
Date: Wed, 27 Apr 2011 16:30:35 -0500
Subject: [PATCH] Add Big* support to Reflector.

---
 src/jvm/clojure/lang/Reflector.java   |   20 ++++++++++++++------
 test/clojure/test_clojure/numbers.clj |   22 ++++++++++++++++------
 2 files changed, 30 insertions(+), 12 deletions(-)

diff --git a/src/jvm/clojure/lang/Reflector.java b/src/jvm/clojure/lang/Reflector.java
index d13bf61..290c149 100644
--- a/src/jvm/clojure/lang/Reflector.java
+++ b/src/jvm/clojure/lang/Reflector.java
@@ -13,6 +13,8 @@
 package clojure.lang;
 
 import java.lang.reflect.*;
+import java.math.BigInteger;
+import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
@@ -383,7 +385,7 @@ static public List getMethods(Class c, int arity, String name, boolean getStatic
 
 	if(methods.isEmpty())
 		methods.addAll(bridgeMethods);
-	
+
 	if(!getStatics && c.isInterface())
 		{
 		allmethods = Object.class.getMethods();
@@ -448,17 +450,23 @@ static public boolean paramArgTypeMatch(Class paramType, Class argType){
 		return true;
 	if(paramType == int.class)
 		return argType == Integer.class
-		       || argType == long.class
-				|| argType == Long.class;// || argType == FixNum.class;
+				|| argType == long.class
+				|| argType == Long.class
+				|| argType == BigInt.class
+				|| argType == BigInteger.class;
 	else if(paramType == float.class)
 		return argType == Float.class
-				|| argType == double.class;
+				|| argType == double.class
+				|| argType == BigDecimal.class;
 	else if(paramType == double.class)
 		return argType == Double.class
-				|| argType == float.class;// || argType == DoubleNum.class;
+				|| argType == float.class
+				|| argType == BigDecimal.class;
 	else if(paramType == long.class)
 		return argType == Long.class
-				|| argType == int.class;// || argType == BigNum.class;
+				|| argType == int.class
+				|| argType == BigInt.class
+				|| argType == BigInteger.class;
 	else if(paramType == char.class)
 		return argType == Character.class;
 	else if(paramType == short.class)
diff --git a/test/clojure/test_clojure/numbers.clj b/test/clojure/test_clojure/numbers.clj
index 301f6e4..7eab074 100644
--- a/test/clojure/test_clojure/numbers.clj
+++ b/test/clojure/test_clojure/numbers.clj
@@ -103,7 +103,7 @@
    [byte             [-1            0           1           Byte/MAX_VALUE  :error           :error             :error                 :error             :error]]
    [unchecked-byte   [-1            0           1           Byte/MAX_VALUE  -1               -1                 -1                     -1                 -1]]
    [short            [-1            0           1           Byte/MAX_VALUE  Short/MAX_VALUE  :error             :error                 :error             :error]]
-   [unchecked-short  [-1            0           1           Byte/MAX_VALUE  Short/MAX_VALUE  -1                 -1                     -1                 -1]] 
+   [unchecked-short  [-1            0           1           Byte/MAX_VALUE  Short/MAX_VALUE  -1                 -1                     -1                 -1]]
    [int              [-1            0           1           Byte/MAX_VALUE  Short/MAX_VALUE  Integer/MAX_VALUE  :error                 :error             :error]]
    [unchecked-int    [-1            0           1           Byte/MAX_VALUE  Short/MAX_VALUE  Integer/MAX_VALUE  -1                     Integer/MAX_VALUE  Integer/MAX_VALUE]]
    [long             [-1            0           1           Byte/MAX_VALUE  Short/MAX_VALUE  Integer/MAX_VALUE  Long/MAX_VALUE         Long/MAX_VALUE     Long/MAX_VALUE]]
@@ -123,10 +123,20 @@
                        (catch IllegalArgumentException e :error)))]
         (is (= vals (map wrapped inputs)))))))
 
-;; *** Functions ***
-
 (defonce DELTA 1e-12)
 
+(deftest test-reflection-for-bignums
+  (are [x y] (= x y)
+    1 (Integer/valueOf 1N)
+    1 (Integer/valueOf (BigInteger. "1"))
+    1 (Long/valueOf 1N)
+    1 (Long/valueOf (BigInteger. "1")))
+  (are [x y] (< (- x y) DELTA)
+    1.5 (Float/valueOf 1.5M)
+    1.5 (Double/valueOf 1.5M)))
+
+;; *** Functions ***
+
 (deftest test-add
   (are [x y] (= x y)
       (+) 0
@@ -300,7 +310,7 @@
   ; divide by zero
   (is (thrown? ArithmeticException (rem 9 0)))
   (is (thrown? ArithmeticException (rem 0 0)))
-  
+
   (are [x y] (= x y)
     (rem 4 2) 0
     (rem 3 2) 1
@@ -331,7 +341,7 @@
     (rem 2 -5) 2
     (rem -2 5) -2
     (rem -2 -5) -2
-    
+
     ; num = 0, div != 0
     (rem 0 3) 0
     (rem 0 -3) 0
@@ -347,7 +357,7 @@
   ; divide by zero
   (is (thrown? ArithmeticException (quot 9 0)))
   (is (thrown? ArithmeticException (quot 0 0)))
-  
+
   (are [x y] (= x y)
     (quot 4 2) 2
     (quot 3 2) 1
-- 
1.7.0.4

