# nearestDiv

## 语法

``y = nearestDiv(x,d)``
``y = nearestDiv(x,d,m)``

## 说明

``y = nearestDiv(x,d)` 返回 `x/d` 舍入到最接近的整数值的结果。`

``y = nearestDiv(x,d,m)` 返回 `x/d` 舍入到 `m` 的最接近倍数的结果。计算 `y` 的数据类型，使得在给定数据类型 `x` 以及 `d` 和 `m` 值的情况下，字长和小数长度的大小足以包含最大和最小可能解。`

## 示例

`nearestDiv(int16(201),10)`
```ans = 20 DataTypeMode: Fixed-point: binary point scaling Signedness: Signed WordLength: 13 FractionLength: 0 ```

`nearestDiv(int16(201),10,7)`
```ans = 21 DataTypeMode: Fixed-point: binary point scaling Signedness: Signed WordLength: 13 FractionLength: 0 ```

```function y = nearestDiv_example(x,d) y = nearestDiv(x,d); end ```

```x = fi(pi); d = fi(2); y = nearestDiv_example(x,d)```
```y = 1 DataTypeMode: Fixed-point: binary point scaling Signedness: Signed WordLength: 2 FractionLength: 0 ```

`codegen nearestDiv_example -args {x, coder.Constant(d)}`
```Code generation successful. ```

```function y = nearestDiv10(x) y = nearestDiv(x,10); end ```
```x = fi(5*pi); y = nearestDiv10(x)```
```y = 1 DataTypeMode: Fixed-point: binary point scaling Signedness: Signed WordLength: 2 FractionLength: 0 ```
`codegen nearestDiv10 -args {x}`
```Code generation successful. ```