• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How ensure numbers are correct for os?

 
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not sure if I'm explaining this correctly but as I understand it, numbers in C++/JNI are not the same across all OS's. So I can't just pass them back and forth with the Java code (through JNI) as though they were exactly the same. So my question is: how am I supposed to do this?

I've been told numerous times that i need to be careful of this but never has anyone actually been able to tell me how to safely use/pass numbers with JNI.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Floating Point arithmetic is standardized (by IEEE-754) for 32 bit and 64 bit (float and double in Java, respectively), so I'd think that results would be pretty much the same on all platforms. Some platforms may be more accurate internally (say 80 bit), but that will be lost when converting it back to Java.

So I'm not sure where the differences would come from; do you have a specific issue you can point to?
 
Dan Bizman
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe there are two issues.

1. On some platforms, ints are 16-bit quantities, and on others they are 32-bit quantities. In the Java platform, of course, an int is always a 32-bit integer.

2. The JNI jlong data type is implemented on the iSeries using a C struct of two integers, instead of a true 8-byte integer. (as one example)

There may be other diff's. As I say, people have told me many times that grabbing integers from C++ and putting them right into java int arrays can lead to mistakes but they can never tell me why or how to ensure the correct passing of numbers.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic