JLink, Double.NaN, and arrays
- To: mathgroup at smc.vnet.net
- Subject: [mg64556] JLink, Double.NaN, and arrays
- From: mmalsbur at vt.edu
- Date: Wed, 22 Feb 2006 05:58:40 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
Is it possible to transfer a general array of doubles from Mathematica to a java program using JLink? The Mathematica function MakeJavaObject can be used to convert a list of real numbers to a double array in Java. However, the function only works if the list contains all real numbers. However, arrays of doubles can contain values other than real numbers. For example, the array {1.0, 2.0, Double.NaN} is valid in Java. Mathematica errored when I tried sending this list to Java. The following Mathematica code illustrates the problem. Needs["JLink`"]; InstallJava[]; LoadJavaClass["java.lang.Double"]; Double`parseDouble["1.0"] (* Returns 1.0 *) Double`parseDouble["NaN"] (* Returns Indeterminate *) Double`parseDouble["Infinity"]; (* Returns Infinity *) MakeJavaObject[{1.0,2.0,3.0}] (* Returns <<JavaObject[[D]>> *) MakeJavaObject[{1.0,2.0,Infinity}] (* Errors *) The final line of code should ideally return a java array with the values {1.0, 2.0, Double.POSITIVE_INFINITY}.