hypot函数、fmod函数

hypot函数、fmod函数看 rosnavigatio 里面的程序经常出现 hypot 这个函数 百度一番发现惊喜 摘抄别人博客如下 hypot 函数 C hypot 函数 C hypot function hypot

大家好,欢迎来到IT知识分享网。

看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);

代码实例:

#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://haidsoft.com/117566.html

(0)
上一篇 2025-11-20 07:15
下一篇 2025-11-20 07:26

相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注微信