Menu

#8 Writing uint data in Java

open
nobody
None
5
2008-02-12
2008-02-12
Philip Cook
No

On line 2028 of Nifti1Dataset.java, a double is cast to an int before being written to disk. This is done the same way for both the INT32 data type and the UINT32 type. Java truncates values after casting to int, so that the result is rounded down to Integer.MAX_VALUE, ie 2^31 - 1.

The result is that some values that can be represented as an unsigned 32-bit int will be rounded down to the largest 32-bit signed int value.

A fix that works for me is to cast the double value to a long, then to an int. The resulting value, when read in as an unsigned int, has the correct value.

Strangely, short does not seem to suffer from this problem.

I did all the tests on Java version 1.5.0_13.

Discussion


Log in to post a comment.

MongoDB Logo MongoDB