MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

JLink, Double.NaN, and arrays


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}.


  • Prev by Date: Re: Greek-Letter Bug? Replacing Print
  • Next by Date: Re: question about Split[...]
  • Previous by thread: Re: Counting the number of paths in a network
  • Next by thread: Re: JLink, Double.NaN, and arrays