📄 mf_trunc.hlp
字号:
{smcl}
{* 25mar2005}{...}
{cmd:help mata trunc()}
{hline}
{* index trunc()}{...}
{* index floor()}{...}
{* index ceil()}{...}
{* index round()}{...}
{* index integers}{...}
{title:Title}
{p 4 8 2}
{bf:[M-5] trunc() -- Round to integer}
{title:Syntax}
{p 8 12 2}
{it:real matrix} {cmd:trunc(}{it:real matrix R}{cmd:)}
{p 8 12 2}
{it:real matrix} {cmd:floor(}{it:real matrix R}{cmd:)}
{p 8 12 2}
{it:real matrix}{bind: }{cmd:ceil(}{it:real matrix R}{cmd:)}
{p 8 12 2}
{it:real matrix} {cmd:round(}{it:real matrix R}{cmd:)}
{p 8 12 2}
{it:real matrix} {cmd:round(}{it:real matrix R}{cmd:,} {it:real matrix U}{cmd:)}
{title:Description}
{p 4 4 2}
These functions convert noninteger values to integers, either by moving
toward 0, moving down, moving up, or rounding. These functions are
typically used with scalar arguments, and they return a scalar in that
case. When used with vectors or matrices, the operation is performed
element-by-element.
{p 4 4 2}
{cmd:trunc(}{it:R}{cmd:)} returns the integer part of {it:R}.
{p 4 4 2}
{cmd:floor(}{it:R}{cmd:)} returns the largest integer {it:i} such that
{it:i} <= {it:R}.
{p 4 4 2}
{cmd:ceil(}{it:R}{cmd:)} returns the smallest integer {it:i} such that
{it:i} >= {it:R}.
{p 4 4 2}
{cmd:round(}{it:R}{cmd:)} returns the integer closest to {it:R}.
{p 4 4 2}
{cmd:round(}{it:R}{cmd:,} {it:U}{cmd:)} returns the values of {it:R}
rounded in units of {it:U}, and is equivalent to
{cmd:round(}({it:R}:/{it:U}){cmd:)}:*{it:U}.
For instance, {cmd:round(}{it:R}{cmd:,} 2{cmd:)} returns {it:R} rounded
to the closest even number.
{cmd:round(}{it:R}{cmd:,} .5{cmd:)} returns {it:R} rounded to the
closest multiple of one half.
{cmd:round(}{it:R}{cmd:,} 1{cmd:)} returns {it:R} rounded to the
closest integer and so is equivalent to {cmd:round(}{it:R}{cmd:)}.
{title:Remarks}
{p 4 4 2}
Remarks are presented under the headings
{bf:Relationship to Stata's functions}
{bf:Examples of rounding}
{title:Relationship to Stata's functions}
{p 4 4 2}
{cmd:trunc()} is equivalent to Stata's {cmd:int()} function.
{p 4 4 2}
{cmd:floor()}, {cmd:ceil()}, and {cmd:round()} are equivalent to
Stata's functions of the same name.
{title:Examples of rounding}
{it:x} {cmd:trunc(}{it:x}{cmd:)} {cmd:floor(}{it:x}{cmd:)} {cmd:ceil(}{it:x}{cmd:)} {cmd:round(}{it:x}{cmd:)}
{hline 53}
1 1 1 1 1
1.3 1 1 2 1
1.6 1 1 2 2
-1 -1 -1 -1 -1
-1.3 -1 -2 -1 -1
-1.6 -1 -2 -1 -2
{hline 53}
{title:Conformability}
{p 4 4 2}
{cmd:trunc(}{it:R}{cmd:)},
{cmd:floor(}{it:R}{cmd:)},
{cmd:ceil(}{it:R}{cmd:)}:
{p_end}
{it:R}: {it:r x c}
{it:result}: {it:r x c}
{cmd:ceil(}{it:R}{cmd:)}:
{it:R}: {it:r x c}
{it:result}: {it:r x c}
{cmd:ceil(}{it:R}{cmd:,} {it:U}{cmd:)}:
{it:R}: {it:r1 x c1}
{it:U}: {it:r2 x c2}, {it:R} and {it:U} r-conformable
{it:result}: max({it:r1},{it:r2}) {it:x} max({it:c1},{it:c2})
{title:Diagnostics}
{p 4 4 2}
Most Stata and Mata functions return missing when arguments contain
missing, and in particular, return {cmd:.} whether the argument is
{cmd:.}, {cmd:.a}, {cmd:.b}, ..., {cmd:.z}. The logic is that
performing the operation on a missing value always results in the
same missing-value result. For example, {cmd:sqrt(.a)==.}
{p 4 4 2}
These functions, however, when passed a missing value, return
the particular missing value. Thus {cmd:trunc(.a)==.a},
{cmd:floor(.b)=.b}, {cmd:ceil(.c)==.c}, and {cmd:round(.d)==.d}.
{p 4 4 2}
In the case of {cmd:round()} with two arguments, this applies to
the first argument and only when the second argument is not missing.
If the second argument is missing (whether {cmd:.}, {cmd:.a}, ...,
or {cmd:.z}), then {cmd:.} is returned.
{title:Source code}
{p 4 4 2}
Functions are built-in.
{title:Also see}
{p 4 13 2}
Manual: {hi:[M-5] trunc()}
{p 4 13 2}
Online: help for
{bf:{help m4_scalar:[M-4] scalar}}
{p_end}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -