学习笔记(86):C语言入门到精通-数学函数-中

编程知识 行业动态 更新时间:2024-06-13 00:20:42

立即学习:https://edu.csdn/course/play/10534/394487?utm_source=blogtoedu

目标
#include <math.h>

#include <stdio.h>
#include <math.h>

void test_floor(const double arg) {
	printf("====test_floor====\n");
	printf("floor(%lf) = %lf\n", arg, floor(arg));
}

void test_fmod(const double x, const double y) {
	printf("====test_fmod====\n");
	printf("fmod(%lf, %lf) = %lf\n", x, y, fmod(x, y));
}

void test_frexp(const double num) {
	double ret = 0.0;
	int exp = 0;
	printf("====test_frexp====\n");
	ret = frexp(num, &exp);
	printf("%lf = %lf * 2^%d \n", num, ret, exp);
}

void test_ldexp(const double num, const int exp) {
	double ret = 0.0;
	printf("====test_frexp====\n");
	// num * (2 ^  exp)
	ret = ldexp(num, exp);
	if (ret == HUGE_VAL) {
		printf("error: ret = %lf\n", HUGE_VAL);
	}
	else {
		printf("%lf * 2^%d = %lf\n", num, exp, ret);
	}
}

int main() {
	test_floor(1.234);
	test_floor(100.234);
	test_floor(1000.234);

	test_fmod(10, 3);
	test_fmod(100, 30);
	test_fmod(10.123, 3.456);

	test_frexp(100);
	test_frexp(1024);

	test_ldexp(1, 10);
	test_ldexp(2, 9);
	test_ldexp(1, 9000);

	return 0;
}

 

更多推荐

学习笔记(86):C语言入门到精通-数学函数-中

本文发布于:2023-03-30 11:56:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/a8cb8cd5b010950f79db21ed015ef273.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:函数   学习笔记   入门   语言   数学

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!