2010a and later parsing of int64() and uint64() ?

In releases before 2010a, literal numbers inside int64() and uint64() calls were understood by MATLAB as meaning to parse the numbers as class double and to call the int64() or uint64() method on the resulting double. For example,
>> uint64(18446744073709551600)
ans =
18446744073709551615
Starting with release 2010a, the literal numbers are instead fully valued at parse time and given appropriate type.
I do not have R2010a or later available, so I would ask that people investigate the limits of that parsing in the new versions and report back.
For example:
  • is uint64(18446744073709551600+0) the same as uint64(18446744073709551600) ?
  • ditto uint64(18446744073709551600*1) ?
  • ditto uint64(+18446744073709551600) ?
  • ditto uint64(18446744073709551600.) ?
  • ditto uint64(18446744073709551600.1) ?
  • ditto uint64(18446744073709551600e0) ?
  • how about int64(2^64-15) ?
  • is uint64(18446744073709551600/2) equal to uint64(9223372036854775800) ?
And more generally, is there any expression X whose absolute value does not exceed 2^53, for which
B = int64(X);
is not the same as
A = X;
B = uint64(A);
?

Respuestas (1)

Friedrich
Friedrich el 12 de Jul. de 2011
Hi,
tested with R2011a 64bit on Win7:
>> int64(18446744073709551600)
ans =
9223372036854775807
>> uint64(18446744073709551600+0)
ans =
18446744073709551615
>> uint64(18446744073709551600*1)
ans =
18446744073709551615
>>
uint64(+18446744073709551600)
ans =
18446744073709551615
>>
uint64(18446744073709551600.)
ans =
18446744073709551615
>> uint64(18446744073709551600.1)
ans =
18446744073709551615
>> uint64(18446744073709551600e0)
ans =
18446744073709551615
>> int64(2^64-15)
ans =
9223372036854775807
>> uint64(18446744073709551600/2)
ans =
9223372036854775808
>> uint64(9223372036854775800)
ans =
9223372036854775800

5 comentarios

Walter Roberson
Walter Roberson el 12 de Jul. de 2011
Thank you!
It appears that if any character is included (including unary plus) that the expression is evaluated as double and that result is converted.
I would appreciate a test with unary plus and with unary minus (negative sign) for int64() and a value in an appropriate range such as 9223372036854775800.
Also, now that I think of it, I would like to inquire about int64(-9223372036854775808)
Walter Roberson
Walter Roberson el 19 de Ag. de 2011
Bump. For completeness, I'd appreciate the last few tests I mentioned so that I am certain that I have understood the parser.
Friedrich
Friedrich el 19 de Ag. de 2011
Hi,
sorry but I don't get your second part with the unary plus and minus. Could you please explain to me what I have to do?
int64(-9223372036854775808)
ans =
-9223372036854775808
Walter Roberson
Walter Roberson el 19 de Ag. de 2011
Thanks. Could I ask you to check int64(+9223372036854775800) ?
Daniel Shub
Daniel Shub el 19 de Ag. de 2011
R2011a 64bit on Linux
>> int64(+9223372036854775800)
ans =
9223372036854775807

Iniciar sesión para comentar.

Categorías

Productos

Etiquetas

Preguntada:

el 12 de Jul. de 2011

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by