Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
64-bit integer arithmetic

Subject: 64-bit integer arithmetic

From: Tam Chu

Date: 22 Aug, 2007 17:43:56

Message: 1 of 20

I am working on a coding algorithm using 64-bit unsigned
integers involving multiplication and division.

MATLAB seems to support up to 53 bits, not the full 64 bits.
Has anyone had any experience with coding 64-bit integer
operations in MATLAB? I'd appreciate any pointer,
comments, etc.

Thanks,
Tam

Subject: 64-bit integer arithmetic

From: John D'Errico

Date: 22 Aug, 2007 18:00:31

Message: 2 of 20

"Tam Chu" <tchu@vectrsystems.com> wrote in message <fahskr$7ae
$1@fred.mathworks.com>...
> I am working on a coding algorithm using 64-bit unsigned
> integers involving multiplication and division.
>
> MATLAB seems to support up to 53 bits, not the full 64 bits.
> Has anyone had any experience with coding 64-bit integer
> operations in MATLAB? I'd appreciate any pointer,
> comments, etc.

Matlab does support 64 bit integers, however the
double precision format only exactly represents
integers up to 53 bits.

help uint64
 UINT64 Convert to unsigned 64-bit integer...

John

Subject: 64-bit integer arithmetic

From: Dan Hensley

Date: 22 Aug, 2007 21:24:12

Message: 3 of 20

John D'Errico wrote:
> "Tam Chu" <tchu@vectrsystems.com> wrote in message <fahskr$7ae
> $1@fred.mathworks.com>...
>> I am working on a coding algorithm using 64-bit unsigned
>> integers involving multiplication and division.
>>
>> MATLAB seems to support up to 53 bits, not the full 64 bits.
>> Has anyone had any experience with coding 64-bit integer
>> operations in MATLAB? I'd appreciate any pointer,
>> comments, etc.
>
> Matlab does support 64 bit integers, however the
> double precision format only exactly represents
> integers up to 53 bits.
>
> help uint64
> UINT64 Convert to unsigned 64-bit integer...


The only issue is that (most?) math operations aren't supported for
uint64. Hopefully some time soon Mathworks will add support.

Dan

Subject: 64-bit integer arithmetic

From: us

Date: 22 Aug, 2007 22:56:57

Message: 4 of 20

Dan Hensley:
<SNIP sad point on non-double support...

> The only issue is that (most?) math operations aren't
supported for uint64...

to see what's supported for any given data type, use

     methods uint64
     methods uint8
     methods single
% and so on

us

Subject: 64-bit integer arithmetic

From: Penny Anderson

Date: 23 Aug, 2007 15:46:09

Message: 5 of 20

"Dan Hensley" <somewhere@over.there> wrote in message
news:jd-dneeqi7XgNFHbnZ2dnUVZ_jydnZ2d@comcast.com...
> John D'Errico wrote:
>> "Tam Chu" <tchu@vectrsystems.com> wrote in message <fahskr$7ae
>> $1@fred.mathworks.com>...
>>> I am working on a coding algorithm using 64-bit unsigned
>>> integers involving multiplication and division.
>>>
>>> MATLAB seems to support up to 53 bits, not the full 64 bits.
>>> Has anyone had any experience with coding 64-bit integer
>>> operations in MATLAB? I'd appreciate any pointer,
>>> comments, etc.
>>
>> Matlab does support 64 bit integers, however the
>> double precision format only exactly represents
>> integers up to 53 bits.
>>
>> help uint64
>> UINT64 Convert to unsigned 64-bit integer...
>
>
> The only issue is that (most?) math operations aren't supported for
> uint64. Hopefully some time soon Mathworks will add support.
>
> Dan

Hi Dan,

What would you like to see working for [u]int64 arithmetic? plus, minus,
more than that? If so, what and why?

Are you OK with the current model of saturation on overflow during
arithmetic? If not, why not?

How would you like double precision floating point interactions with 64 bit
integer quantities to be handled?

Do you have a need for complex integer arithmetic at all? Currently that is
not supported for any size of integer data type.

Thanks,

Penny Anderson
The MathWorks, Inc.

Subject: 64-bit integer arithmetic

From: Dan Hensley

Date: 23 Aug, 2007 21:25:48

Message: 6 of 20

Penny Anderson wrote:
>
> Hi Dan,
>
> What would you like to see working for [u]int64 arithmetic? plus, minus,
> more than that? If so, what and why?

I've submitted enhancement requests through tech support in the past,
but what I'd like at minimum is +, -, .*, and ./. I use int64s as
identifiers in some objects of mine. I need to increment the
identifiers, hence the need for +. I used int64 to ensure that I never
hit a 32bit overflow.

> Are you OK with the current model of saturation on overflow during
> arithmetic? If not, why not?

I'm not sure what I prefer here. In my case I should never see an overflow.

> How would you like double precision floating point interactions with 64 bit
> integer quantities to be handled?

I would think that the left-most quantity defines the data type that the
other inputs would be cast to. i.e.

double(3) + int64(2) => double(5)
int64(3) + double(2) => int64(5)

> Do you have a need for complex integer arithmetic at all? Currently that is
> not supported for any size of integer data type.

I don't.

Dan

Subject: 64-bit integer arithmetic

From: Roman

Date: 1 Oct, 2007 10:35:49

Message: 7 of 20

Hi,

> What would you like to see working for [u]int64
> arithmetic? plus, minus, more than that? If so,
> what and why?

At an absolute minimum, + and - at least. Example: I need to
construct a 64-bit mask to use in bitand. The mask should
consist of N 1-bits. The usual way to do this is 1<<N - 1.
In Matlab this would be bitshift(uint64(1), N) - 1, except
that the -1 cannot be done. What a shame.

Of course I could work around this using bitset, but as you
can imagine that is quite clumsy in comparison.

Subject: 64-bit integer arithmetic

From: Tam Chu

Date: 16 Oct, 2007 16:57:53

Message: 8 of 20

"Penny Anderson" <penny@mathworks.com> wrote in message
<faka41$j37$1@fred.mathworks.com>...
> "Dan Hensley" <somewhere@over.there> wrote in message
> news:jd-dneeqi7XgNFHbnZ2dnUVZ_jydnZ2d@comcast.com...
> > John D'Errico wrote:
> >> "Tam Chu" <tchu@vectrsystems.com> wrote in message
<fahskr$7ae
> >> $1@fred.mathworks.com>...
> >>> I am working on a coding algorithm using 64-bit unsigned
> >>> integers involving multiplication and division.
> >>>
> >>> MATLAB seems to support up to 53 bits, not the full 64
bits.
> >>> Has anyone had any experience with coding 64-bit integer
> >>> operations in MATLAB? I'd appreciate any pointer,
> >>> comments, etc.
> >>
> >> Matlab does support 64 bit integers, however the
> >> double precision format only exactly represents
> >> integers up to 53 bits.
> >>
> >> help uint64
> >> UINT64 Convert to unsigned 64-bit integer...
> >
> >
> > The only issue is that (most?) math operations aren't
supported for
> > uint64. Hopefully some time soon Mathworks will add
support.
> >
> > Dan
>
> Hi Dan,
>
> What would you like to see working for [u]int64
arithmetic? plus, minus,
> more than that? If so, what and why?
>
> Are you OK with the current model of saturation on
overflow during
> arithmetic? If not, why not?
>
> How would you like double precision floating point
interactions with 64 bit
> integer quantities to be handled?
>
> Do you have a need for complex integer arithmetic at all?
Currently that is
> not supported for any size of integer data type.
>
> Thanks,
>
> Penny Anderson
> The MathWorks, Inc.
>
>

Penny,

Do you have some idea when the 64-bit integer enhancements
will be released?

I think the MATLAB online documentation is not accurate as
it indicates that uint64 operations (+,-,*,/) are supported.
Do you know of any solution to doing these operations for 64
 bit quantities using 32-bit operations?

Thanks,
Tam Chu

Subject: 64-bit integer arithmetic

From: Penny Anderson

Date: 17 Oct, 2007 18:01:15

Message: 9 of 20

"Tam Chu" <tchu@vectrsystems.com> wrote in message
news:ff2qih$fcm$1@fred.mathworks.com...
> "Penny Anderson" <penny@mathworks.com> wrote in message
> <faka41$j37$1@fred.mathworks.com>...
>> Hi Dan,
>>
>> What would you like to see working for [u]int64
> arithmetic? plus, minus,
>> more than that? If so, what and why?
>>
>> Are you OK with the current model of saturation on
> overflow during
>> arithmetic? If not, why not?
>>
>> How would you like double precision floating point
> interactions with 64 bit
>> integer quantities to be handled?
>>
>> Do you have a need for complex integer arithmetic at all?
> Currently that is
>> not supported for any size of integer data type.
>>
>> Thanks,
>>
>> Penny Anderson
>> The MathWorks, Inc.
>>
>>
>
> Penny,
>
> Do you have some idea when the 64-bit integer enhancements
> will be released?
>
> I think the MATLAB online documentation is not accurate as
> it indicates that uint64 operations (+,-,*,/) are supported.
> Do you know of any solution to doing these operations for 64
> bit quantities using 32-bit operations?
>
> Thanks,
> Tam Chu

Hi Tam,

There is no immediate plan to release 64 bit integer arithmetic in MATLAB.
We are still trying to gauge interest in such a feature.

Is this link in the doc what you mean:

http://www.mathworks.com/access/helpdesk/help/techdoc/index.html?/access/helpdesk/help/techdoc/ref/uint32.html&

You are correct, this is misleading, it should clarify that the math is only
available for 8, 16 & 32 bit integer data types.

I don't know of a quick way to implement +, -, .*, ./ for int64 using int32,
I'm afraid. Have you tried searching through MATLAB Central?

Penny.

Subject: 64-bit integer arithmetic

From: dpb

Date: 17 Oct, 2007 18:05:15

Message: 10 of 20

Penny Anderson wrote:
> "Tam Chu" <tchu@vectrsystems.com> wrote in message
> news:ff2qih$fcm$1@fred.mathworks.com...
>> "Penny Anderson" <penny@mathworks.com> wrote in message
>> <faka41$j37$1@fred.mathworks.com>...
>>> Hi Dan,
>>>
>>> What would you like to see working for [u]int64
>> arithmetic? plus, minus,
>>> more than that? If so, what and why?
>>>
>>> Are you OK with the current model of saturation on
>> overflow during
>>> arithmetic? If not, why not?
>>>
>>> How would you like double precision floating point
>> interactions with 64 bit
>>> integer quantities to be handled?
>>>
>>> Do you have a need for complex integer arithmetic at all?
>> Currently that is
>>> not supported for any size of integer data type.
>>>
>>> Thanks,
>>>
>>> Penny Anderson
>>> The MathWorks, Inc.
>>>
>>>
>> Penny,
>>
>> Do you have some idea when the 64-bit integer enhancements
>> will be released?
>>
>> I think the MATLAB online documentation is not accurate as
>> it indicates that uint64 operations (+,-,*,/) are supported.
>> Do you know of any solution to doing these operations for 64
>> bit quantities using 32-bit operations?
>>
>> Thanks,
>> Tam Chu
>
> Hi Tam,
>
> There is no immediate plan to release 64 bit integer arithmetic in MATLAB.
> We are still trying to gauge interest in such a feature.
>
> Is this link in the doc what you mean:
>
> http://www.mathworks.com/access/helpdesk/help/techdoc/index.html?/access/helpdesk/help/techdoc/ref/uint32.html&
>
> You are correct, this is misleading, it should clarify that the math is only
> available for 8, 16 & 32 bit integer data types.
>
> I don't know of a quick way to implement +, -, .*, ./ for int64 using int32,
...

I guess my thought if it were required for something I was doing would
be to use a compiler supporting 8-byte integers and add the
functionality needed in a mex file.

Not knowing the objective (and as the original post has disappeared from
my newsserver so not aware of the initial question), don't know how
feasible an overall solution this would be...

--

Subject: 64-bit integer arithmetic

From: Kris Thielemans

Date: 20 Jun, 2008 13:15:03

Message: 11 of 20

"Penny Anderson" <penny@mathworks.com> wrote in message
<ff5ilb$l6h$1@fred.mathworks.com>...
>
> There is no immediate plan to release 64 bit integer
arithmetic in MATLAB.
> We are still trying to gauge interest in such a feature.

Dear Penny

please register my interest as well. At least basic math
operations (+,-/*,/,sum,diff etc). It seems strange that
this isn't supported even on 64 bit machines.

We are using matlab for medical imaging in PET, where
calculations with high number of counts are common.

thanks

Kris

Subject: 64-bit integer arithmetic

From: Steve Eddins

Date: 20 Jun, 2008 13:32:39

Message: 12 of 20

Kris Thielemans wrote:
> "Penny Anderson" <penny@mathworks.com> wrote in message
> <ff5ilb$l6h$1@fred.mathworks.com>...
>> There is no immediate plan to release 64 bit integer
> arithmetic in MATLAB.
>> We are still trying to gauge interest in such a feature.
>
> Dear Penny
>
> please register my interest as well. At least basic math
> operations (+,-/*,/,sum,diff etc). It seems strange that
> this isn't supported even on 64 bit machines.
>
> We are using matlab for medical imaging in PET, where
> calculations with high number of counts are common.
>
> thanks
>
> Kris

Kris,

Do you have counts higher than 2^53? You can get exact integer
representation and arithmetic up to that level by using double-precision
floating point.

Steve

Subject: 64-bit integer arithmetic

From: Combo

Date: 2 Dec, 2008 09:36:02

Message: 13 of 20

Steve Eddins <Steve.Eddins@mathworks.com> wrote in message <g3gbhn$otg$1@fred.mathworks.com>...
> Kris Thielemans wrote:
> > "Penny Anderson" <penny@mathworks.com> wrote in message
> > <ff5ilb$l6h$1@fred.mathworks.com>...
> >> There is no immediate plan to release 64 bit integer
> > arithmetic in MATLAB.
> >> We are still trying to gauge interest in such a feature.
> >
> > Dear Penny
> >
> > please register my interest as well. At least basic math
> > operations (+,-/*,/,sum,diff etc). It seems strange that
> > this isn't supported even on 64 bit machines.
> >
> > We are using matlab for medical imaging in PET, where
> > calculations with high number of counts are common.
> >
> > thanks
> >
> > Kris
>
> Kris,
>
> Do you have counts higher than 2^53? You can get exact integer
> representation and arithmetic up to that level by using double-precision
> floating point.
>
> Steve

I'd also like to add my name to the list. The lack of support for uint64 manipulations precludes implementation of a lot of otherwise straightforward manipulations in cryptographic protocols, which frequently rely on 64 bit data blocks. Please implement it.

Subject: 64-bit integer arithmetic

From: tristram.scott@ntlworld.com (Tristram Scott)

Date: 2 Dec, 2008 11:42:24

Message: 14 of 20

Combo <none@none.com> wrote:
> Steve Eddins <Steve.Eddins@mathworks.com> wrote in message
> <g3gbhn$otg$1@fred.mathworks.com>...
>> Kris Thielemans wrote:
>> > "Penny Anderson" <penny@mathworks.com> wrote in message
>> > <ff5ilb$l6h$1@fred.mathworks.com>...
>> >> There is no immediate plan to release 64 bit integer
>> > arithmetic in MATLAB.
>> >> We are still trying to gauge interest in such a feature.
>> >
[snip]

>
> I'd also like to add my name to the list. The lack of support for uint64
> manipulations precludes implementation of a lot of otherwise
> straightforward manipulations in cryptographic protocols, which frequently
> rely on 64 bit data blocks. Please implement it.

Yes please. I often pass in flags to switchyard style functions using
integers. Having 64 bit resolution on these would be superb, as it would
allow the choice of combinations of up to 64 different features.

if bitand(zi.dataflag,localbooleanflags('PricePlot'))
% Plot some prices
end

As well as that, though, 64 bit arithmetic makes for much simpler
comparison between MATLAB prototype code and final version C code. This
has caused me some troubles in the past when looking at random number
generators.

--
Dr Tristram J. Scott
Energy Consultant

Subject: 64-bit integer arithmetic

From: Mike

Date: 2 Apr, 2009 14:30:18

Message: 15 of 20

"Kris Thielemans" <kris.thielemans@imperial.ac.uk> wrote in message <g3gagn$h1r$1@fred.mathworks.com>...
> "Penny Anderson" <penny@mathworks.com> wrote in message
> <ff5ilb$l6h$1@fred.mathworks.com>...
> >
> > There is no immediate plan to release 64 bit integer
> arithmetic in MATLAB.
> > We are still trying to gauge interest in such a feature.
>
> Dear Penny
>
> please register my interest as well. At least basic math
> operations (+,-/*,/,sum,diff etc). It seems strange that
> this isn't supported even on 64 bit machines.
>
> We are using matlab for medical imaging in PET, where
> calculations with high number of counts are common.
>
> thanks
>
> Kris

If you're in dire need of performing operations with that level of precision, consider the use of a "bigint" approach - the simple (but by no means efficient - and honestly 'quick and dirty') method is conversion of numbers to strings and performing operations on the resulting strings. If you need numerical values, you can easily split the strings in chunks and then multiply by the correct power of 10.

Here's a quick sample:

function number = toBigInt(n);
  number = '';
  while n ~= 0
    number = [char(mod(n,10)+'0') number];
    n = floor(n/10);
  end
end

And adding two big numbers?

function s3 = addBigInt(s1,s2);

% if s1,s2 == [] answer = 0
if length(s1) < 1 && length(s2) < 1 s3 = '0';
elseif length(s1) < 1 s3 = s2; % if s1 == [] then s2 is the answer
elseif length(s2) < 1 s3 = s1; % if s2 == [] then s1 is the answer
else
  carry = 0; % define the carry
  s3 = ''; % define the answer
  dh = max(length(s1),length(s2));
  for i=1:dh
    if i <= length(s1) n1 = s1(length(s1)+1-i)-'0'; else n1 = 0; end
    if i <= length(s2) n2 = s2(length(s2)+1-i)-'0'; else n2 = 0; end
    n = n1 + n2 + carry; % add the ith digits of s1, s2 and carry
    carry = floor(n/10); % save the carry
    s3 = [char(mod(n,10)+'0') s3]; % compute the answer digit
  end
  if carry > 0 s3 = [char(carry+'0') s3]; end
end

More files located: http://blog.kryptohardware.com/2009/04/01/64-bit-numbers-in-matlaboctave

Subject: 64-bit integer arithmetic

From: Petter

Date: 17 Jul, 2009 10:25:02

Message: 16 of 20

"Tam Chu" <tchu@vectrsystems.com> wrote in message <fahskr$7ae$1@fred.mathworks.com>...
> MATLAB seems to support up to 53 bits, not the full 64 bits.
> Has anyone had any experience with coding 64-bit integer
> operations in MATLAB? I'd appreciate any pointer,
> comments, etc.

"INT64 arithmetic in MATLAB" on the File Exchange: http://www.mathworks.com/matlabcentral/fileexchange/24725

--
Petter

Subject: 64-bit integer arithmetic

From: Adam Wyatt

Date: 13 Apr, 2010 17:36:23

Message: 17 of 20

"Petter " <petter.strandmark@home.se> wrote in message <h3pjhu$fvc$1@fred.mathworks.com>...
> "Tam Chu" <tchu@vectrsystems.com> wrote in message <fahskr$7ae$1@fred.mathworks.com>...
> > MATLAB seems to support up to 53 bits, not the full 64 bits.
> > Has anyone had any experience with coding 64-bit integer
> > operations in MATLAB? I'd appreciate any pointer,
> > comments, etc.
>
> "INT64 arithmetic in MATLAB" on the File Exchange: http://www.mathworks.com/matlabcentral/fileexchange/24725
>
> --
> Petter

Please oh please introduce basic 64 bit integer arithmetic (+, -, *, /, .*, ./). Supposedly linsolve is supported, but not plus or minus - how strange!

Subject: 64-bit integer arithmetic

From: Markus Leuthold

Date: 9 Feb, 2011 15:14:04

Message: 18 of 20

Matlab uses uint64 for built-in classes, but we cannot use it without casting!

m=containers.Map;
m.Count + 1

fails! Please either support basic arithmetic operations for uint64 or drop this datatype in favour of "double" for built-in classes

best regards, Kusi

Subject: 64-bit integer arithmetic

From: Steven_Lord

Date: 9 Feb, 2011 15:28:16

Message: 19 of 20



"Markus Leuthold" <matlab3@titlis.org> wrote in message
news:iiuavs$r89$1@fred.mathworks.com...
> Matlab uses uint64 for built-in classes, but we cannot use it without
> casting!
>
> m=containers.Map;
> m.Count + 1
>
> fails! Please either support basic arithmetic operations for uint64 or
> drop this datatype in favour of "double" for built-in classes

Done. Take a look at the Release Notes from release R2010b.

http://www.mathworks.com/help/techdoc/rn/bsk8h3i-1.html

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: 64-bit integer arithmetic

From: Derek O'Connor

Date: 10 Feb, 2011 08:56:03

Message: 20 of 20

"Steven_Lord" <slord@mathworks.com> wrote in message <iiubqg$ohk$1@fred.mathworks.com>...
>
>
> "Markus Leuthold" <matlab3@titlis.org> wrote in message
> news:iiuavs$r89$1@fred.mathworks.com...
> > Matlab uses uint64 for built-in classes, but we cannot use it without
> > casting!
> >
> > m=containers.Map;
> > m.Count + 1
> >
> > fails! Please either support basic arithmetic operations for uint64 or
> > drop this datatype in favour of "double" for built-in classes
>
> Done. Take a look at the Release Notes from release R2010b.
>
> http://www.mathworks.com/help/techdoc/rn/bsk8h3i-1.html
>
> --
> Steve Lord
> slord@mathworks.com
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com
------------------------------

Steve,

Would you please enumerate the *limitations* of 64-bit integer operations vis a vis double precision operations.

For example, (1) is matrix multiplication possible?, (2) is scalar integer arithmetic (+,-,*) slower or faster than the double precision equivalent?, etc., etc., etc.

Derek O'Connor

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us