How do I get real integer overflows in MATLAB/Octave?

后端 未结 6 1604
天涯浪人
天涯浪人 2020-11-28 14:31

I\'m working on a verification-tool for some VHDL-Code in MATLAB/Octave. Therefore I need data types which generate \"real\" overflows:

intmax(\'int32\') + 1         


        
6条回答
  •  自闭症患者
    2020-11-28 15:05

    Hm, yes...

    Actually, I was able to solve the problem with my custom "overflow"-Subroutine... Now it runs painfully slow, but without unexpected behaviour! My mistake was a missing round(), since Matlab/Octave will introduce small errors.

    But if someone knows a faster solution, I would be glad to try it!

    function ret = overflow_sg(arg,bw)
    
        % remove possible rounding errors, and prepare returnvalue (if number is inside boundaries, nothing will happen)
        ret = round(arg);
    
        argsize = size(ret);
    
        for i = 1:argsize(1)
            for j = 1:argsize(2)
                ret(i,j) = flow_sg(ret(i,j),bw);
            end
        end
    
    end%function
    
    %---
    
    function ret = flow_sg(arg,bw)
        ret = arg;
        while (ret < (-2^(bw-1)))
            ret = ret + 2^bw;
        end
    
        % Check for overflows:
        while (ret > (2^(bw-1)-1))
            ret = ret - 2^bw;
        end
    end%function
    

提交回复
热议问题