看ros navigation里面的程序经常出现hypot这个函数,百度一番发现惊喜:摘抄别人博客如下:
一、hypot函数
C ++ hypot()函数 (C++ hypot() function)
hypot() function is a library function of cmath header, it is used to find the hypotenuse of the given numbers, it accepts two numbers and returns the calculated result of hypotenuse i.e. sqrt(x*x + y*y).
hypot()函数是cmath标头的库函数,用于查找给定数字的斜边,接受两个数字并返回斜边的计算结果,即sqrt(x * x + y * y) 。
Syntax of hypot() function:
hypot()函数的语法:
hypot(x, y); //(1)
讯享网
Parameter(s): x, y – numbers to be calculated hypotenuse (or sqrt(x*x + y*y))
参数: x,y –要计算的斜边数(或sqrt(x * x + y * y) )
Return value: double – it returns double value that is the result of the expression sqrt(x*x + y*y).
返回值: double-它返回double值,该值是表达式sqrt(x * x + y * y)的结果 。
简化我们平时写得特别啰嗦的:
讯享网sqrt(pow(x, 2) + pow(y, 2));
还有这样的语法格式:
hypot(x, y, z); //等价与sqrt(pow(x,2) + pow(y,2) + pow(z,2))
二.fmod()函数
函数字面理解float mod (浮点数的模)
hypot()函数是math.h标头的库函数,#include <math.h>
fmod() 用来对浮点数进行取模(求余),其原型为: double fmod (double x, double y);
设返回值为 ret,那么 x = n * y + ret,其中 n 是整数,ret 和 x 有相同的符号,而且 ret 的绝对值小于 y 的绝对值。如果 x = 0,那么 ret = NaN。
fmod 函数计算 x 除以 y 的 f 浮点余数,这样 x = i*y + f,其中 i 是整数,f 和 x 有相同的符号,而且 f 的绝对值小于 y 的绝对值。
代码实例:
讯享网#include <stdio.h> #include <math.h> int main () { printf ( "fmod of 5.3 / 2 is %f\n", fmod (5.3,2) ); printf ( "fmod of 18.5 / 4.2 is %f\n", fmod (18.5,4.2) ); return 0; }
输出结果:

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/125512.html