You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by "José Pinto (JIRA)" <ji...@apache.org> on 2006/12/04 21:49:22 UTC

[jira] Created: (IO-101) The method EndianUtils.writeSwappedDouble() and EndianUtils.readSwappedDouble() do not match!

The method EndianUtils.writeSwappedDouble() and EndianUtils.readSwappedDouble() do not match!
---------------------------------------------------------------------------------------------

                 Key: IO-101
                 URL: http://issues.apache.org/jira/browse/IO-101
             Project: Commons IO
          Issue Type: Bug
          Components: Streams/Writers
    Affects Versions: 1.2
         Environment: I was running Windows XP SP2 and using Commons IO 1.2, Java 1.5 update 9 when I got this problem.
            Reporter: José Pinto
            Priority: Critical


Code:

public static void main(String[] args) {

		double[] tests = new double[] {34.345, -345.5645, 545.12, 10.043, 7.123456789123};
		for (int i = 0; i< tests.length ;i++) {
			byte[] buffer = new byte[8];			
			EndianUtils.writeSwappedDouble(buffer, 0, tests[i]);
			double val = EndianUtils.readSwappedDouble(buffer, 0);
			System.out.println(val);	
		}
		 
}

Result:
34.344969482421874
-345.5645
545.11951171875
10.043
7.123456789123

Note:
In my opinion the values shouldn't be changed at all.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


[jira] Commented: (IO-101) The method EndianUtils.writeSwappedDouble() and EndianUtils.readSwappedDouble() do not match!

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/IO-101?page=comments#action_12455776 ] 
            
Henri Yandell commented on IO-101:
----------------------------------

Yup. The code is based on two things - the Double.longBitsToDouble pair of methods and the readSwappedLong pair of methods. The former pass with your data (yay JDK!), but the latter fail; so this bug is in the Long methods. Will keep investigating.

> The method EndianUtils.writeSwappedDouble() and EndianUtils.readSwappedDouble() do not match!
> ---------------------------------------------------------------------------------------------
>
>                 Key: IO-101
>                 URL: http://issues.apache.org/jira/browse/IO-101
>             Project: Commons IO
>          Issue Type: Bug
>          Components: Streams/Writers
>    Affects Versions: 1.2
>         Environment: I was running Windows XP SP2 and using Commons IO 1.2, Java 1.5 update 9 when I got this problem.
>            Reporter: José Pinto
>            Priority: Critical
>             Fix For: 1.4
>
>
> Code:
> public static void main(String[] args) {
> 		double[] tests = new double[] {34.345, -345.5645, 545.12, 10.043, 7.123456789123};
> 		for (int i = 0; i< tests.length ;i++) {
> 			byte[] buffer = new byte[8];			
> 			EndianUtils.writeSwappedDouble(buffer, 0, tests[i]);
> 			double val = EndianUtils.readSwappedDouble(buffer, 0);
> 			System.out.println(val);	
> 		}
> 		 
> }
> Result:
> 34.344969482421874
> -345.5645
> 545.11951171875
> 10.043
> 7.123456789123
> Note:
> In my opinion the values shouldn't be changed at all.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


[jira] Commented: (IO-101) The method EndianUtils.writeSwappedDouble() and EndianUtils.readSwappedDouble() do not match!

Posted by "José Pinto (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/IO-101?page=comments#action_12455804 ] 
            
José Pinto commented on IO-101:
-------------------------------

Thanks Henri!
I also think this should be fixed as soon as possible because it's a very difficult problem to track. I noticed only because I was reading latitudes and longitudes from little endian byte streams...

> The method EndianUtils.writeSwappedDouble() and EndianUtils.readSwappedDouble() do not match!
> ---------------------------------------------------------------------------------------------
>
>                 Key: IO-101
>                 URL: http://issues.apache.org/jira/browse/IO-101
>             Project: Commons IO
>          Issue Type: Bug
>          Components: Streams/Writers
>    Affects Versions: 1.2
>         Environment: I was running Windows XP SP2 and using Commons IO 1.2, Java 1.5 update 9 when I got this problem.
>            Reporter: José Pinto
>            Priority: Critical
>             Fix For: 1.3
>
>         Attachments: IO-101.patch
>
>
> Code:
> public static void main(String[] args) {
> 		double[] tests = new double[] {34.345, -345.5645, 545.12, 10.043, 7.123456789123};
> 		for (int i = 0; i< tests.length ;i++) {
> 			byte[] buffer = new byte[8];			
> 			EndianUtils.writeSwappedDouble(buffer, 0, tests[i]);
> 			double val = EndianUtils.readSwappedDouble(buffer, 0);
> 			System.out.println(val);	
> 		}
> 		 
> }
> Result:
> 34.344969482421874
> -345.5645
> 545.11951171875
> 10.043
> 7.123456789123
> Note:
> In my opinion the values shouldn't be changed at all.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


[jira] Updated: (IO-101) The method EndianUtils.writeSwappedDouble() and EndianUtils.readSwappedDouble() do not match!

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/IO-101?page=all ]

Henri Yandell updated IO-101:
-----------------------------

    Fix Version/s: 1.4

Assigning for looking at in 1.4. Looks like we're having classic data loss due to the data type, so might not be a simple fix.

A unit test should be very easy to create from José's data above.

> The method EndianUtils.writeSwappedDouble() and EndianUtils.readSwappedDouble() do not match!
> ---------------------------------------------------------------------------------------------
>
>                 Key: IO-101
>                 URL: http://issues.apache.org/jira/browse/IO-101
>             Project: Commons IO
>          Issue Type: Bug
>          Components: Streams/Writers
>    Affects Versions: 1.2
>         Environment: I was running Windows XP SP2 and using Commons IO 1.2, Java 1.5 update 9 when I got this problem.
>            Reporter: José Pinto
>            Priority: Critical
>             Fix For: 1.4
>
>
> Code:
> public static void main(String[] args) {
> 		double[] tests = new double[] {34.345, -345.5645, 545.12, 10.043, 7.123456789123};
> 		for (int i = 0; i< tests.length ;i++) {
> 			byte[] buffer = new byte[8];			
> 			EndianUtils.writeSwappedDouble(buffer, 0, tests[i]);
> 			double val = EndianUtils.readSwappedDouble(buffer, 0);
> 			System.out.println(val);	
> 		}
> 		 
> }
> Result:
> 34.344969482421874
> -345.5645
> 545.11951171875
> 10.043
> 7.123456789123
> Note:
> In my opinion the values shouldn't be changed at all.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


[jira] Commented: (IO-101) The method EndianUtils.writeSwappedDouble() and EndianUtils.readSwappedDouble() do not match!

Posted by "José Pinto (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/IO-101?page=comments#action_12455586 ] 
            
José Pinto commented on IO-101:
-------------------------------

I tried using the java.nio Buffer for the same purpose and it worked as expected. Maybe we should look for differences in the code.

> The method EndianUtils.writeSwappedDouble() and EndianUtils.readSwappedDouble() do not match!
> ---------------------------------------------------------------------------------------------
>
>                 Key: IO-101
>                 URL: http://issues.apache.org/jira/browse/IO-101
>             Project: Commons IO
>          Issue Type: Bug
>          Components: Streams/Writers
>    Affects Versions: 1.2
>         Environment: I was running Windows XP SP2 and using Commons IO 1.2, Java 1.5 update 9 when I got this problem.
>            Reporter: José Pinto
>            Priority: Critical
>             Fix For: 1.4
>
>
> Code:
> public static void main(String[] args) {
> 		double[] tests = new double[] {34.345, -345.5645, 545.12, 10.043, 7.123456789123};
> 		for (int i = 0; i< tests.length ;i++) {
> 			byte[] buffer = new byte[8];			
> 			EndianUtils.writeSwappedDouble(buffer, 0, tests[i]);
> 			double val = EndianUtils.readSwappedDouble(buffer, 0);
> 			System.out.println(val);	
> 		}
> 		 
> }
> Result:
> 34.344969482421874
> -345.5645
> 545.11951171875
> 10.043
> 7.123456789123
> Note:
> In my opinion the values shouldn't be changed at all.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


[jira] Updated: (IO-101) The method EndianUtils.writeSwappedDouble() and EndianUtils.readSwappedDouble() do not match!

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/IO-101?page=all ]

Henri Yandell updated IO-101:
-----------------------------

    Attachment: IO-101.patch

Patch and bugfix for this issue.

> The method EndianUtils.writeSwappedDouble() and EndianUtils.readSwappedDouble() do not match!
> ---------------------------------------------------------------------------------------------
>
>                 Key: IO-101
>                 URL: http://issues.apache.org/jira/browse/IO-101
>             Project: Commons IO
>          Issue Type: Bug
>          Components: Streams/Writers
>    Affects Versions: 1.2
>         Environment: I was running Windows XP SP2 and using Commons IO 1.2, Java 1.5 update 9 when I got this problem.
>            Reporter: José Pinto
>            Priority: Critical
>             Fix For: 1.4
>
>         Attachments: IO-101.patch
>
>
> Code:
> public static void main(String[] args) {
> 		double[] tests = new double[] {34.345, -345.5645, 545.12, 10.043, 7.123456789123};
> 		for (int i = 0; i< tests.length ;i++) {
> 			byte[] buffer = new byte[8];			
> 			EndianUtils.writeSwappedDouble(buffer, 0, tests[i]);
> 			double val = EndianUtils.readSwappedDouble(buffer, 0);
> 			System.out.println(val);	
> 		}
> 		 
> }
> Result:
> 34.344969482421874
> -345.5645
> 545.11951171875
> 10.043
> 7.123456789123
> Note:
> In my opinion the values shouldn't be changed at all.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


[jira] Resolved: (IO-101) The method EndianUtils.writeSwappedDouble() and EndianUtils.readSwappedDouble() do not match!

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/IO-101?page=all ]

Henri Yandell resolved IO-101.
------------------------------

    Resolution: Fixed

Thanks Robert, 

I've made that change.

svn ci -m "Applying Robert Michel's more correct patch for #IO-101. "
Sending        src/java/org/apache/commons/io/EndianUtils.java
Transmitting file data .
Committed revision 484864.

> The method EndianUtils.writeSwappedDouble() and EndianUtils.readSwappedDouble() do not match!
> ---------------------------------------------------------------------------------------------
>
>                 Key: IO-101
>                 URL: http://issues.apache.org/jira/browse/IO-101
>             Project: Commons IO
>          Issue Type: Bug
>          Components: Streams/Writers
>    Affects Versions: 1.2
>         Environment: I was running Windows XP SP2 and using Commons IO 1.2, Java 1.5 update 9 when I got this problem.
>            Reporter: José Pinto
>            Priority: Critical
>             Fix For: 1.3
>
>         Attachments: IO-101.patch
>
>
> Code:
> public static void main(String[] args) {
> 		double[] tests = new double[] {34.345, -345.5645, 545.12, 10.043, 7.123456789123};
> 		for (int i = 0; i< tests.length ;i++) {
> 			byte[] buffer = new byte[8];			
> 			EndianUtils.writeSwappedDouble(buffer, 0, tests[i]);
> 			double val = EndianUtils.readSwappedDouble(buffer, 0);
> 			System.out.println(val);	
> 		}
> 		 
> }
> Result:
> 34.344969482421874
> -345.5645
> 545.11951171875
> 10.043
> 7.123456789123
> Note:
> In my opinion the values shouldn't be changed at all.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


[jira] Updated: (IO-101) The method EndianUtils.writeSwappedDouble() and EndianUtils.readSwappedDouble() do not match!

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/IO-101?page=all ]

Henri Yandell updated IO-101:
-----------------------------

    Fix Version/s: 1.3
                       (was: 1.4)

Moving the fix version up to 1.3 because I think it's good to go in 1.3, but I don't want to charge in committing it without consensus.

> The method EndianUtils.writeSwappedDouble() and EndianUtils.readSwappedDouble() do not match!
> ---------------------------------------------------------------------------------------------
>
>                 Key: IO-101
>                 URL: http://issues.apache.org/jira/browse/IO-101
>             Project: Commons IO
>          Issue Type: Bug
>          Components: Streams/Writers
>    Affects Versions: 1.2
>         Environment: I was running Windows XP SP2 and using Commons IO 1.2, Java 1.5 update 9 when I got this problem.
>            Reporter: José Pinto
>            Priority: Critical
>             Fix For: 1.3
>
>         Attachments: IO-101.patch
>
>
> Code:
> public static void main(String[] args) {
> 		double[] tests = new double[] {34.345, -345.5645, 545.12, 10.043, 7.123456789123};
> 		for (int i = 0; i< tests.length ;i++) {
> 			byte[] buffer = new byte[8];			
> 			EndianUtils.writeSwappedDouble(buffer, 0, tests[i]);
> 			double val = EndianUtils.readSwappedDouble(buffer, 0);
> 			System.out.println(val);	
> 		}
> 		 
> }
> Result:
> 34.344969482421874
> -345.5645
> 545.11951171875
> 10.043
> 7.123456789123
> Note:
> In my opinion the values shouldn't be changed at all.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


[jira] Commented: (IO-101) The method EndianUtils.writeSwappedDouble() and EndianUtils.readSwappedDouble() do not match!

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/IO-101?page=comments#action_12455796 ] 
            
Henri Yandell commented on IO-101:
----------------------------------

[That has to be the most annoying thing.... I'd done a beautiful write up as I worked through this and the damn machine froze... I'd got used to that not being a problem]

Anyways....

Your first double of 34.345 leads to the following input and output when passed through writeSwapped and readSwapped:

4630030446347063132 is 0x40412C28,F5C28F5C
4630030442052095836 is 0x40412C27,F5C28F5C

Output of writeXxx is

92, -113, -62, -11, 40, 44, 65, 64 which is:
5C,   8F,  C2,  F5, 28, 2C, 41, 40

so by inspection that's correct. So the problem is in the readSwapped method.

In readSwapped we get two longs, a high and a low. The high is 1078012968, which is 0x40412C28. So that's good.
The low is -171798692. The negative is a bit worrisome there. According to OS X Calculator it should be 4123168604, 
which I can confirm as that gives the correct answer when added to (high << 32).

Looking at the calculation of the low long, we get four numbers that are added together: 

92, 36608, 12713984, -184549376

Again the negative is worrisome. Assuming it is incorrect and the others are correct, it should be 4110417920.
This is a big number, so I bet we have an int which is wrapping. Changing the line from:

( data[ offset + 3 ] & 0xff ) << 24;

to 

( (long) ( data[ offset + 3 ] & 0xff )) << 24;

gives the correct answer. Shifting 0xff by 8, 16 and 24, only 24 goes over the top. So I think we only need this on the two '<< 24' lines.

> The method EndianUtils.writeSwappedDouble() and EndianUtils.readSwappedDouble() do not match!
> ---------------------------------------------------------------------------------------------
>
>                 Key: IO-101
>                 URL: http://issues.apache.org/jira/browse/IO-101
>             Project: Commons IO
>          Issue Type: Bug
>          Components: Streams/Writers
>    Affects Versions: 1.2
>         Environment: I was running Windows XP SP2 and using Commons IO 1.2, Java 1.5 update 9 when I got this problem.
>            Reporter: José Pinto
>            Priority: Critical
>             Fix For: 1.4
>
>
> Code:
> public static void main(String[] args) {
> 		double[] tests = new double[] {34.345, -345.5645, 545.12, 10.043, 7.123456789123};
> 		for (int i = 0; i< tests.length ;i++) {
> 			byte[] buffer = new byte[8];			
> 			EndianUtils.writeSwappedDouble(buffer, 0, tests[i]);
> 			double val = EndianUtils.readSwappedDouble(buffer, 0);
> 			System.out.println(val);	
> 		}
> 		 
> }
> Result:
> 34.344969482421874
> -345.5645
> 545.11951171875
> 10.043
> 7.123456789123
> Note:
> In my opinion the values shouldn't be changed at all.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


[jira] Reopened: (IO-101) The method EndianUtils.writeSwappedDouble() and EndianUtils.readSwappedDouble() do not match!

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/IO-101?page=all ]

Henri Yandell reopened IO-101:
------------------------------

             
Consider Robert's change to the patch [sounds good to me]

> The method EndianUtils.writeSwappedDouble() and EndianUtils.readSwappedDouble() do not match!
> ---------------------------------------------------------------------------------------------
>
>                 Key: IO-101
>                 URL: http://issues.apache.org/jira/browse/IO-101
>             Project: Commons IO
>          Issue Type: Bug
>          Components: Streams/Writers
>    Affects Versions: 1.2
>         Environment: I was running Windows XP SP2 and using Commons IO 1.2, Java 1.5 update 9 when I got this problem.
>            Reporter: José Pinto
>            Priority: Critical
>             Fix For: 1.3
>
>         Attachments: IO-101.patch
>
>
> Code:
> public static void main(String[] args) {
> 		double[] tests = new double[] {34.345, -345.5645, 545.12, 10.043, 7.123456789123};
> 		for (int i = 0; i< tests.length ;i++) {
> 			byte[] buffer = new byte[8];			
> 			EndianUtils.writeSwappedDouble(buffer, 0, tests[i]);
> 			double val = EndianUtils.readSwappedDouble(buffer, 0);
> 			System.out.println(val);	
> 		}
> 		 
> }
> Result:
> 34.344969482421874
> -345.5645
> 545.11951171875
> 10.043
> 7.123456789123
> Note:
> In my opinion the values shouldn't be changed at all.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


[jira] Commented: (IO-101) The method EndianUtils.writeSwappedDouble() and EndianUtils.readSwappedDouble() do not match!

Posted by "Robert Michel (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/IO-101?page=comments#action_12456131 ] 
            
Robert Michel commented on IO-101:
----------------------------------

Henri,

I came across this bug just yesterday and saw your patch today.  Separately, I had come up with an alternate fix which you might want to consider.

The older code fails whenever the byte at offset+3 is negative.  The int isn't wrapping, but it is extending the sign when the int is cast up to long.  The sign extension is what needs to be clipped.

The byte at offset+7 is not affected, because the variable it enters (high) is shifted left 32, obliterating the sign bit.

The current solution converts the byte at offset+3 to a long, which fixes this but will silently upcast the other bytes to long to accomplish the additions.  I suspect the original author had intended to do all the swapping in ints for performance reasons.   (If performance wasn't an issue, this method could be done in a single line.)  I'm guessing that the casts to long and the addition on the last line shoud be the only 64-bit operations.

My alternative:

    public static long readSwappedLong(byte[] data, int offset) {
        int low = (
            ( ( data[ offset + 0 ] & 0xff ) << 0 ) +
            ( ( data[ offset + 1 ] & 0xff ) << 8 ) +
            ( ( data[ offset + 2 ] & 0xff ) << 16 ) +
            ( ( data[ offset + 3 ] & 0xff ) << 24 ) );
        int high = (
            ( ( data[ offset + 4 ] & 0xff ) << 0 ) +
            ( ( data[ offset + 5 ] & 0xff ) << 8 ) +
            ( ( data[ offset + 6 ] & 0xff ) << 16 ) +
            ( ( data[ offset + 7 ] & 0xff ) << 24 ) );
        return ((long)high << 32) + (0xffffffffL & low);
    }

This solution indicates (a little more clearly?) that the original two statements are 32-bit ops and the last statement is the 64-bit work. 

FYI, I used this test to demonstrate the problem locally:

    public static void main(String[] args) {
        
        byte[] buffer = {
                0, 0, 0, -1, 1, 2, 3, 4
        };
        long val = EndianUtils.readSwappedLong(buffer, 0);
        ByteBuffer bb = ByteBuffer.allocate(8);
        bb.putLong(val);
        bb.flip();
        for (int i = 0; i < 8; i++) {
            System.out.println(bb.get() + " ");
        }
        System.out.println();
        
    }

> The method EndianUtils.writeSwappedDouble() and EndianUtils.readSwappedDouble() do not match!
> ---------------------------------------------------------------------------------------------
>
>                 Key: IO-101
>                 URL: http://issues.apache.org/jira/browse/IO-101
>             Project: Commons IO
>          Issue Type: Bug
>          Components: Streams/Writers
>    Affects Versions: 1.2
>         Environment: I was running Windows XP SP2 and using Commons IO 1.2, Java 1.5 update 9 when I got this problem.
>            Reporter: José Pinto
>            Priority: Critical
>             Fix For: 1.3
>
>         Attachments: IO-101.patch
>
>
> Code:
> public static void main(String[] args) {
> 		double[] tests = new double[] {34.345, -345.5645, 545.12, 10.043, 7.123456789123};
> 		for (int i = 0; i< tests.length ;i++) {
> 			byte[] buffer = new byte[8];			
> 			EndianUtils.writeSwappedDouble(buffer, 0, tests[i]);
> 			double val = EndianUtils.readSwappedDouble(buffer, 0);
> 			System.out.println(val);	
> 		}
> 		 
> }
> Result:
> 34.344969482421874
> -345.5645
> 545.11951171875
> 10.043
> 7.123456789123
> Note:
> In my opinion the values shouldn't be changed at all.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


[jira] Resolved: (IO-101) The method EndianUtils.writeSwappedDouble() and EndianUtils.readSwappedDouble() do not match!

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/IO-101?page=all ]

Henri Yandell resolved IO-101.
------------------------------

    Resolution: Fixed

svn ci -m "Committing my patch from #IO-101, fixing an <int> overrun in readSwappedLong. Many thanks to José Pinto for finding this" src/

Sending        src/java/org/apache/commons/io/EndianUtils.java
Sending        src/test/org/apache/commons/io/EndianUtilsTest.java
Transmitting file data ..
Committed revision 482841.

----

It'll be available in the nightly build tonight José, and in IO 1.3 which should get released sometime this month (IO-99 willing).

> The method EndianUtils.writeSwappedDouble() and EndianUtils.readSwappedDouble() do not match!
> ---------------------------------------------------------------------------------------------
>
>                 Key: IO-101
>                 URL: http://issues.apache.org/jira/browse/IO-101
>             Project: Commons IO
>          Issue Type: Bug
>          Components: Streams/Writers
>    Affects Versions: 1.2
>         Environment: I was running Windows XP SP2 and using Commons IO 1.2, Java 1.5 update 9 when I got this problem.
>            Reporter: José Pinto
>            Priority: Critical
>             Fix For: 1.3
>
>         Attachments: IO-101.patch
>
>
> Code:
> public static void main(String[] args) {
> 		double[] tests = new double[] {34.345, -345.5645, 545.12, 10.043, 7.123456789123};
> 		for (int i = 0; i< tests.length ;i++) {
> 			byte[] buffer = new byte[8];			
> 			EndianUtils.writeSwappedDouble(buffer, 0, tests[i]);
> 			double val = EndianUtils.readSwappedDouble(buffer, 0);
> 			System.out.println(val);	
> 		}
> 		 
> }
> Result:
> 34.344969482421874
> -345.5645
> 545.11951171875
> 10.043
> 7.123456789123
> Note:
> In my opinion the values shouldn't be changed at all.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org