作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我从 Fortran 转换为 C++ 的代码包含 spacing(x)
功能。从描述来看,spacing(x)
返回
Smallest distance between two numbers of a given type
Determines the distance between the argument X and the nearest adjacent number of the same type.
最佳答案
使用 SPACING
如 Determines the distance between the argument X and the nearest adjacent number of the same type , 使用 nexttoward()
.
upper = nexttoward(x, INFINITY) - x;
lower = x - nexttoward(x, -INFINITY);
spacing = fmin(upper, lower);
upper != lower
在特定情况下:例如
x
是 2 的幂。
if (x > 0) {
spacing = x - nexttoward(x, 0);
} else {
// 1.0 used here instead of 0 to handle x==0
spacing = nexttoward(x, 1.0) - x;
}
或
// Subtract next smaller-in-magnitude value. With 0, use next toward 1.
spacing = fabs(x - nexttoward(x, !x));
nextafter()
效果与
nexttoward()
一样好,甚至更好.
关于c++ - 如何在 C++ 中实现 Fortran 间距()函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69683869/
我是一名优秀的程序员,十分优秀!