Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function t = test_is_int()
- % See: http://stackoverflow.com/a/6916862/97160
- % create a vector of doubles, containing integers and non-integers
- x = (1:1e5)';
- idx = ( rand(size(x)) < 0.5 );
- x(idx) = x(idx) + rand(sum(idx(:)),1);
- % create functions to test
- funcs = {@func1; @func2; @func3; @func4};
- % timeit and store results
- t = zeros(size(funcs));
- v = cell(size(funcs));
- for i=1:numel(funcs)
- f = @() funcs{i}(x);
- t(i) = timeit(f);
- v{i} = feval(f);
- end
- assert( isequal(v{:}) )
- end
- function v = func1(x)
- v = ~mod(x,1);
- end
- function v = func2(x)
- v = x==double(uint64(x));
- end
- function v = func3(x)
- v = x==floor(x);
- end
- function v = func4(x)
- v = x==round(x);
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement