当前位置:网站首页>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 ).
边栏推荐
- zfoo增加类似于mydog的路由
- 云计算笔记part.2——应用管理
- Circular linked list OJ question
- Data system of saltstack
- Leetcode day3 find duplicate email addresses
- Kubeedge releases white paper on cloud native edge computing threat model and security protection technology
- [C language] scanf format input and modifier summary
- editor.md中markdown编辑器的实现
- leetcode day3 超过经理收入的员工
- [C language] print pattern summary
猜你喜欢

数字滤波器设计——Matlab

Cloud computing notes part.1 - system management

时间转日期的sql语句应该怎么写?

Tencent cloud deployment lamp_ Experience of building a station

CodeIgnier框架实现restful API接口编程

Const pointer of C language and parameter passing of main function

How many types of rain do you know?

中国能否在元宇宙的未来发展中取得突破,占领高地?

毕马威中国:证券基金经营机构信息技术审计项目发现洞察

Integration and implementation of login click graphic verification code in personal blog system
随机推荐
Integration and implementation of login click graphic verification code in personal blog system
Common modules of saltstack
Use Hal Library of STM32 to drive 1.54 inch TFT screen (240*240 st7789v)
河北:稳粮扩豆助力粮油生产提质增效
【经验之谈】关于维修电子设备的几点建议和经验
Kubeedge releases white paper on cloud native edge computing threat model and security protection technology
Implementation of memmove in C language
Leetcode day2 连续出现的数字
Know small and medium LAN WLAN
Intermediate soft test (system integration project management engineer) high frequency test site
Why is there no log output in the telnet login interface?
MySQL8 Encrypting InnoDB Tablespaces
editor.md中markdown编辑器的实现
Information management system and games based on C language
Implementation of strstr in C language
Prometheus deployment
[NPP installation plug-in]
C+ + core programming
CDGA|工业互联网行业怎么做好数据治理?
Use of strtok and strError