3

The find function within matlab returns indices where the given locigal argument evaluates true.
Thus I'm wondering, why the return values (for the indices) are of type double and not uint32 or uint64 like the biggest index into a matrix could be.
Another strange thing which might be connected to that here is, that running

[~,max_num_of_elem]=computer

returns the maximal number of elements allowed for a matrix in the variable max_num_of_elem which is also of type double.

Bastian Ebeling
  • 1,138
  • 11
  • 38
  • 2
    `find` can return indices **and** values. I assume you are asking about the data type of the indices, not the values. – am304 Sep 04 '13 at 11:45
  • Oh, sorry am304 - of course you are right. I'll adopt the question accordingly. – Bastian Ebeling Sep 04 '13 at 11:58
  • 1
    `double` is Matlab's native type. Almost everything uses it and returns it. This was a design choice and in many cases make it a lot easier as one can directly use the values returned in equations without having to convert them. The only issue is that `find` likely won't work for for matrices with more than `2^53` elements. – horchler Sep 07 '13 at 18:42
  • 1
    @horchler: actually the [maximum number of elements](http://www.mathworks.com/help/matlab/ref/computer.html) on 64-bit architectures is `2^48 -1`. That is still way more than anything you'll ever need, as it amounts to a vector of 256 tera one-byte elements ((2^48-1)/2^40 = 256) or a `double` vector of size 32TB (terabytes as in 1024 GB!). Keep in mind that on Windows, that is even larger than the memory limit allowed by the OS: http://msdn.microsoft.com/en-us/library/aa366778.aspx . So I dont see the problem here :) – Amro Sep 08 '13 at 15:33
  • 1
    @Amro: Well that's good news for `find` then. I was simply quoting the largest double integer before they start not all having exact floating-point representations. – horchler Sep 08 '13 at 19:51
  • @horchler: yes that's true, double-precision floating-point numbers have significand with 52+1 bits of precision. So the range of exactly representable integers is `[-2^53,+2^53]`. Beyond this, the spacing starts to double for every range `[2^n,2^(n+1)]`. That's why `eps(2^53)==2`, `eps(2^54)==4`, and so on.. https://en.wikipedia.org/wiki/Double-precision_floating-point_format – Amro Sep 09 '13 at 19:16

1 Answers1

6

I can only guess, but probably because a wide range of functions only support double. Run

setdiff(methods('double'), methods('uint32'))

to see what functions are defined for double and not for uint32 on your version of MATLAB.

Also there is the overflow issue with integer data types in MATLAB that can introduce some hard to detect bugs.

Mohsen Nosratinia
  • 9,844
  • 1
  • 27
  • 52
  • 1
    probably also because of historical reasons; MATLAB originally only had `double` type, and it was not until later releases that other types were introduced: http://blogs.mathworks.com/steve/2013/01/15/data-types/ – Amro Sep 06 '13 at 13:51