Forum Stats

  • 3,852,779 Users
  • 2,264,136 Discussions
  • 7,905,138 Comments

Discussions

JNI return double with NaN

863941
863941 Member Posts: 2
edited May 24, 2011 2:53PM in Java Native Interface (JNI)
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

Answers

  • EJP
    EJP Member Posts: 32,920 Gold Crown
    edited May 24, 2011 4:36AM
    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.
  • 863941
    863941 Member Posts: 2
    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. :)
  • EJP
    EJP Member Posts: 32,920 Gold Crown
    '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.
  • jschellSomeoneStoleMyAlias
    jschellSomeoneStoleMyAlias Member Posts: 24,877 Gold Badge
    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.
This discussion has been closed.