Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why would I want to cast a matlab enumeration to int32?

Today i stepped into this code snippet:

classdef (Enumeration,Sealed) ClassBlabla < int8
    enumeration
        ALPHA(0)
        BETA(1)
        GAMMA(2)
    end

    methods (static)
        function ret = doSomething()
            ret = containers.Map(.......)
            for i = int32(ClassBlabla.ALPHA):int32(ClassBlabla.GAMMA)
                ret(i) = somethingelse(blablabla(i))
            end
         end
    end
end

What is that int32(...) in the for?? A cast? Why do I want to cast to int32? Isn't ALPHA already 0 and GAMMA already 2??

like image 794
Alessandro L. Avatar asked Nov 03 '22 04:11

Alessandro L.


1 Answers

It's to widen the ALPHA and GAMMA values fro int8 to int32. Most likely, that's because either the blablabla() function expects an int32 input, or the ret value is expected to have int32 keys. ALPHA and GAMMA are already 0 and 2, but they are int8 instead of int32, and blablabla() or clients of doSomething() may not play well with int8 values. (You can tell ALPHA and GAMMA are int8 because of the ClasBlabla < int8 at the top.)

like image 62
Andrew Janke Avatar answered Nov 10 '22 20:11

Andrew Janke