4 Replies Latest reply: May 24, 2011 1:53 PM by jschellSomeoneStoleMyAlias RSS

    JNI return double with NaN

    863941
      check my code first.

      JNIEXPORT jdouble JNICALL Java_Test_getDouble(JNIEnv *env, jclass unused, jlong v)
      {
      double d = -2.71000;
      return (jdouble)d;
      }
      When Test.getDouble() is called in java, NaN is returned.
      Can someone tell me what is going on here and how can I fixed it?

      I am using MIPS gcc compiler (mips-linux-gnu-gcc) along with the option -msoft-float.
      Thanks in advance.

      Sam
        • 1. Re: JNI return double with NaN
          EJP
          1. What's 'v' for?

          2. What's the JNI for? You can return constant double values in Java, you don't need JNI or C or MIPS compilers for that.
          • 2. Re: JNI return double with NaN
            863941
            v is not connected with this question.
            My point is the JNI return is not what I expect, using constant double just make question simple. :)
            • 3. Re: JNI return double with NaN
              EJP
              'v' is a parameter to the method so of course it is relevant. I'm wondering whether you have changed the signature of the Java method without regenerating the header file and changing the signature in the C file accordingly.
              • 4. Re: JNI return double with NaN
                jschellSomeoneStoleMyAlias
                860938 wrote:
                JNIEXPORT jdouble JNICALL Java_Test_getDouble(JNIEnv *env, jclass unused, jlong v)
                {
                double d = -2.71000;
                return (jdouble)d;
                }
                When Test.getDouble() is called in java, NaN is returned.
                Can someone tell me what is going on here and how can I fixed it?
                Without having actually tried the code my first guess would be that this is not your problem.

                I suspect that if I did try the code it wouldn't return the result you are seeing. Thus there would be two possibilities.
                1. You are not running the code that you are posting here.
                2. Something is wrong with the way you are compiling it.

                If I remember I will try the code you posted.