#35497 [Bgs]: Difference between echo and printf

2005-11-30 Thread viperjason at gmail dot com
 ID:   35497
 User updated by:  viperjason at gmail dot com
 Reported By:  viperjason at gmail dot com
 Status:   Bogus
 Bug Type: Scripting Engine problem
 Operating System: Windows XP SP2
 PHP Version:  5CVS-2005-11-30 (CVS)
 New Comment:

I thought ints were 32bits?  0x800F is a 32 bit value.


Previous Comments:


[2005-11-30 23:11:00] [EMAIL PROTECTED]

$a = 0x800F;
In this case $a is bigger than int, so the engine converts it to float
automatically.
printf(%d) casts it back to int and you get negative value as the
result.
echo (int)$a; will give you the same.
In all the other cases echo  printf() give the very same results.
No bug here.



[2005-11-30 22:51:59] viperjason at gmail dot com

Description:

If you look at the code I initialize a 32bit hex value and print it
with both printf and echo.  I do a AND and a OR to get the value back
to the original value and print it again with printf and echo.

Printf and echo disaggree on the first print
Printf and echo agree on the second print
Printf and echo agree on the third print.

What happened with the first print?
I realize you use signed integers.but where is my sign?


Reproduce code:
---
?
$a = 0x800F;
printf(hex=%x, dec=%d by printf\n,$a,$a);
echo $a.by echo\n;
$a = $a  0x0FFF;
printf(hex=%x, dec=%d by printf\n,$a,$a);
echo $a.\n;
$a = $a | 0x8000;
printf(hex=%x, dec=%d by printf\n,$a,$a);
echo $a.\n;
?


Expected result:

I expect both printf and echo to consistantly print out the same
decimal result.

Actual result:
--
The first time they didnt and second time they did.





-- 
Edit this bug report at http://bugs.php.net/?id=35497edit=1


#35497 [Bgs]: Difference between echo and printf

2005-11-30 Thread tony2001
 ID:   35497
 Updated by:   [EMAIL PROTECTED]
 Reported By:  viperjason at gmail dot com
 Status:   Bogus
 Bug Type: Scripting Engine problem
 Operating System: Windows XP SP2
 PHP Version:  5CVS-2005-11-30 (CVS)
 New Comment:

/usr/include/limits.h:
#define LONG_MAX 2147483647L

# php -r 'var_dump(0x.dechex(2147483647));'
string(10) 0x7fff

# php -r 'var_dump(0x800F);'
float(2147483663)


Previous Comments:


[2005-12-01 00:54:13] viperjason at gmail dot com

I thought ints were 32bits?  0x800F is a 32 bit value.



[2005-11-30 23:11:00] [EMAIL PROTECTED]

$a = 0x800F;
In this case $a is bigger than int, so the engine converts it to float
automatically.
printf(%d) casts it back to int and you get negative value as the
result.
echo (int)$a; will give you the same.
In all the other cases echo  printf() give the very same results.
No bug here.



[2005-11-30 22:51:59] viperjason at gmail dot com

Description:

If you look at the code I initialize a 32bit hex value and print it
with both printf and echo.  I do a AND and a OR to get the value back
to the original value and print it again with printf and echo.

Printf and echo disaggree on the first print
Printf and echo agree on the second print
Printf and echo agree on the third print.

What happened with the first print?
I realize you use signed integers.but where is my sign?


Reproduce code:
---
?
$a = 0x800F;
printf(hex=%x, dec=%d by printf\n,$a,$a);
echo $a.by echo\n;
$a = $a  0x0FFF;
printf(hex=%x, dec=%d by printf\n,$a,$a);
echo $a.\n;
$a = $a | 0x8000;
printf(hex=%x, dec=%d by printf\n,$a,$a);
echo $a.\n;
?


Expected result:

I expect both printf and echo to consistantly print out the same
decimal result.

Actual result:
--
The first time they didnt and second time they did.





-- 
Edit this bug report at http://bugs.php.net/?id=35497edit=1


#35497 [Bgs]: Difference between echo and printf

2005-11-30 Thread viperjason at gmail dot com
 ID:   35497
 User updated by:  viperjason at gmail dot com
 Reported By:  viperjason at gmail dot com
 Status:   Bogus
 Bug Type: Scripting Engine problem
 Operating System: Windows XP SP2
 PHP Version:  5CVS-2005-11-30 (CVS)
 New Comment:

so in order to get a negative to display I have to cast it to an INT ?

var_dump(dechex(-1)) = 0x
var_dump(0x) = float(4294967295)
var_dump((int)0x) = int(-1)


Previous Comments:


[2005-12-01 01:12:15] [EMAIL PROTECTED]

/usr/include/limits.h:
#define LONG_MAX 2147483647L

# php -r 'var_dump(0x.dechex(2147483647));'
string(10) 0x7fff

# php -r 'var_dump(0x800F);'
float(2147483663)



[2005-12-01 00:54:13] viperjason at gmail dot com

I thought ints were 32bits?  0x800F is a 32 bit value.



[2005-11-30 23:11:00] [EMAIL PROTECTED]

$a = 0x800F;
In this case $a is bigger than int, so the engine converts it to float
automatically.
printf(%d) casts it back to int and you get negative value as the
result.
echo (int)$a; will give you the same.
In all the other cases echo  printf() give the very same results.
No bug here.



[2005-11-30 22:51:59] viperjason at gmail dot com

Description:

If you look at the code I initialize a 32bit hex value and print it
with both printf and echo.  I do a AND and a OR to get the value back
to the original value and print it again with printf and echo.

Printf and echo disaggree on the first print
Printf and echo agree on the second print
Printf and echo agree on the third print.

What happened with the first print?
I realize you use signed integers.but where is my sign?


Reproduce code:
---
?
$a = 0x800F;
printf(hex=%x, dec=%d by printf\n,$a,$a);
echo $a.by echo\n;
$a = $a  0x0FFF;
printf(hex=%x, dec=%d by printf\n,$a,$a);
echo $a.\n;
$a = $a | 0x8000;
printf(hex=%x, dec=%d by printf\n,$a,$a);
echo $a.\n;
?


Expected result:

I expect both printf and echo to consistantly print out the same
decimal result.

Actual result:
--
The first time they didnt and second time they did.





-- 
Edit this bug report at http://bugs.php.net/?id=35497edit=1