manually-written floor function code for rounding non-integers
古いコメントを表示
Hi,
I need your help. See what I get when I used edit to view the steps involved into the floor function. It is a built-in function but I still want to see the mathematics on which this floor function is based on via matlab codes. Can you help? E.g., If floor (2.3) = 2. I want to see a mathematical expression that grabs 2 and/or discards 0.3 to output 2.
%FLOOR Round towards minus infinity.
% FLOOR(X) rounds the elements of X to the nearest integers
% towards minus infinity.
%
% See also ROUND, CEIL, FIX.
% Copyright 1984-2005 The MathWorks, Inc.
% Built-in function.
採用された回答
その他の回答 (2 件)
If floor (2.3) = 2. I want to see a mathematical expression that grabs 2 and/or discards 0.3 to output 2.
There is no fundamental formula for the floor function. In C\C++ it is done simply by casting the input to an integer type. One way to implement it manually though would be,
myfloor(2.3)
function y=myfloor(x)
y=str2double( extractBefore(string(x),'.') );
end
Kapil Gupta
2021 年 7 月 8 日
0 投票
I assume you want to know some details regarding the floor function. The following MATLAB documentation contains some details, you can check this out:
カテゴリ
ヘルプ センター および File Exchange で Elementary Math についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
