当前位置:网站首页>2. Floating point number, the difference between float and double in C language and how to choose them
2. Floating point number, the difference between float and double in C language and how to choose them
2022-07-28 20:05:00 【A programmer who loves playing badminton】
- First we need to know ,float,double stay C The language means The set of real Numbers , And decimals in C In language The default is double type .
- float It belongs to single precision floating-point data ,double It belongs to double precision floating-point data . The meaning of this sentence is double The accuracy of higher than float.float Occupy 4 Bytes of memory , and double Occupy 8 Bytes .
- float Only available 6 Significant digits , Generally speaking, absolutely 6 position , Probably 7 It should be 6~7 position ,double Can provide 16 Significant digits .
- Generally speaking ,CPU Processing single precision floating-point numbers is faster than processing double precision floating-point numbers , If you don't declare , The default decimal is double type , So if you want to use float Words , It has to be forced to turn ,eg:float a = 1.24546f;
float a = 1.24324556; double b = 1.24324556; float c = 1.24324556; double d = 1.24324556; printf("a=%f\n", a); printf("b=%f\n", b); printf("c=%.8f\n", c); printf("d=%.8f\n", d);
1. We go through a and b The output of can be seen ,%f perhaps %lf Indicates that the default output is six decimal places , Less than six to 0 A filling , More than six digits are rounded off .
2. adopt c and d The output of can be seen %.8f It means to output eight decimal places , and float type Of C Because it can only be kept after the decimal point 6~7 position , So it is rounded , and double Type of d It can output accurately .
How to select and use float still double Well ?
For programmers ,double and float Is the difference between the double High precision , Significant figures 16 position ,float precision 7 position . but double Memory consumption is float Twice as many ,double The speed of computing is faster than float Much slower ,C The name of mathematical function in language double and float Different , Don't write wrong , Don't use double precision when you can use single precision ( To save memory , Speed up the calculation ).
边栏推荐
- [network] communication across regional networks learn how routing tables work
- Servlet学习笔记
- 数字滤波器设计——Matlab
- [C language] guessing numbers game [function]
- Getting started with enterprise distributed crawler framework
- 冲刺金九银十丨熬夜半个月汇集大厂Android岗1600道面试真题
- [C language] initial C language reflection and summary
- Design of air combat game based on qtgui image interface
- NetCoreAPI操作Excel表格
- 软考中级(系统集成项目管理工程师)高频考点
猜你喜欢

Basic usage of docker

Article translation software - batch free translation software supports major translation interfaces

There is a 'single quotation mark' problem in the string when Oracle inserts data

adb remount of the / superblock failed: Permission denied

Oracle insert数据时字符串中有‘单引号问题

Thoroughly understand bit operations - shift left, shift right
![[C language] random number generation and `include < time. H > 'learning](/img/bb/3e47bf2e3b25653d9048884d65cda3.png)
[C language] random number generation and `include < time. H > 'learning

Implementation of markdown editor in editor.md

String中常用的API
![[C language] function](/img/81/c185e2bb5eccc13433483f9558f52a.png)
[C language] function
随机推荐
Leetcode day3 find duplicate email addresses
leetcode day4 部门工资最高的员工
Array method added in ES6
BeanFactory not initialized or already closed - call ‘refresh‘ before accessing beans via the Applic
Crawl IP
河北邯郸:拓展基层就业空间 助力高校毕业生就业
Implementation of markdown editor in editor.md
Common modules of saltstack
通信网络基础知识01
CodeIgnier框架实现restful API接口编程
【经验之谈】关于维修电子设备的几点建议和经验
MySQL8 Status Variables: Internal Temporary Tables and Files
Labelme (I)
C language function
JS batch add event listening onclick this event delegate target currenttarget onmouseenter OnMouseOver
Oracle insert数据时字符串中有‘单引号问题
Cloud computing notes part.1 - system management
基于 MinIO 对象存储保障 Rancher 数据
Implementation of strcat in C language
Failed to install app-debug. apk: Failure [INSTALL_FAILED_TEST_ONLY: installPackageLI]