Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

How ensure numbers are correct for os?  RSS feed

 
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
  • 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: 43009
76
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
I am Arthur, King of the Britons. And this is a tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!