Integer challenge.

August 6, 2009 at 8:00 pm (matlab is bad at math, Simple trivia about its fundamental behavior that you probably can't answer, unexpressive language, unsystematic type system)

The ninth Mersenne prime is 261 – 1 = 2305843009213693951. Try to cause MATLAB to represent this value in a simple variable, then display it.

For example here is a Python session that passes by direct calculation:

>>> x = pow(2,61) - 1
>>> x
2305843009213693951L

That obtained the value by calculation, but no mathematical sophistication should be required to stuff a number in a variable. In fact, you may want to see if there’s any way you can simply type the number in to MATLAB and have it represented, as you see here in Python:

>>> x = 2305843009213693951
>>> x
2305843009213693951L

MATLAB has built-in uint64 and int64 data types that are, in principle, able to hold this value, so you should have no problem either way. Heh.

(A contrived example, you suggest? I have experiments running in MATLAB that communicate with a simple data acquisition device, one that has an onboard 64-bit timer/counter; I need to read and set that timer.)

Permalink 1 Comment

Follow

Get every new post delivered to your Inbox.