help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to enter large integers (uint64) without truncation


From: Mike Miller
Subject: Re: How to enter large integers (uint64) without truncation
Date: Tue, 29 Nov 2016 15:30:59 -0800
User-agent: NeoMutt/20161104 (1.7.1)

On Tue, Nov 29, 2016 at 19:16:21 +0100, Kire Pudsje wrote:
>  How to enter large uint64 number in matlab?
> 
> >>x = uint64(2626262626262626262)
> x = 2626262626262626304
> 
> In hex the numbers are respectively
> 24 72 5B F1 AD 44 AF D6
> 24 72 5B F1 AD 44 B0 00
> 
> So the number of significant bits is truncated. Looks like the number first
> is interpreted as being a double, and then converted to uint64.

Right. This is a known limitation of Octave's parser. There has been
some discussion on how to fix it but it is still an open issue in
version 4.2.0.

> As a workaround I enter the number in two parts, which works.
> x = uint64(262626262626262)*10000+6262
> x = 2626262626262626262
> 
> Any better way to enter a large constant?

You could also use the `typecast` function to convert an array of
shorter integers into a long integer, for example

  >> x = typecast (uint32 ([0xAD44AFD6 0x24725BF1]), "uint64")
  x = 2626262626262626262
  >> x = typecast (uint8 ([0xD6 0xAF 0x44 0xAD 0xF1 0x5B 0x72 0x24]), "uint64")
  x = 2626262626262626262

Personally, if I had to work with uint64 arrays in Octave as it stands
today, I would probably write them to a text file and use the load
command, which does seem to handle uint64 values correctly.

-- 
mike



reply via email to

[Prev in Thread] Current Thread [Next in Thread]