Created
October 18, 2018 12:34
-
-
Save noname007/bf25c7f053d164a833ddfd881741d4e0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include | |
int main() { | |
double a = 0.58, *aptr = &a; | |
float af = 0.58, *afptr = ⁡ | |
printf(“%lu,%lx\n”,sizeof(a), *(long int *)aptr); | |
printf(“%lu,%x\n”,sizeof(af), *(int *)afptr); | |
// printf(“%lu,%d”,sizeof(a),(int) (a * 100) ); | |
// int b = 21; | |
// printf(“%lu, %p\n”, sizeof(b), b); | |
// printf(“%lu, %d\n”, sizeof(b), (int)(float) b); | |
return 0; | |
} |
> (= 1.000000001 1.000000002)
#f
> (= 1.0000000000001 1.0000000000002)
#f
> (= 1.000000000000001 1.000000000000002)
#f
> (= 1.0000000000000001 1.0000000000000002)
#f
> (= 1.00000000000000001 1.00000000000000002)
#t
> (= 10000000000000000.1 10000000000000000.2)
#t
<?php
$b = 1.0001;
$c = 1.0002;
var_dump($b == $c); // Y:F B:T X:T -------> false
$b = 1.000000001;
$c = 1.000000002;
var_dump($b == $c); //Y:F B:F X:F -------> false
$b = 1.00000000000000001;
$c = 1.00000000000000002;
var_dump($b == $c); //Y:T B:T X:T -------> true
$b = 1.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001;
$c = 1.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002;
var_dump($b == $c); //Y:T B:T X:~ -------> true
问题:
- 浮点数能表示的最大数,(非正无穷) 是个整数,还是个浮点数
- printf 的输出
float c = (1 << 24); // 16777216.000000
float b = c - 1, d = c + 1, e = d + 1, f = e + 1; // 16777215.000000 16777216.000000 16777216.000000 16777216.000000 16777216.000000
printf("%f %f %f %f %f\n",b, c, d, e, f);
//float b = c - 1, d = c + 1, e = c + 2, f = c + 3;//16777215.000000 16777216.000000 16777216.000000 16777218.000000 16777220.000000
//printf("%f %f %f %f %f\n",b, c, d, e, f);
100.000100000000000332 == 100.000100000000000333 // true
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
good tools
https://babbage.cs.qc.cuny.edu/IEEE-754.old/Decimal.html
http://tool.oschina.net/hexconvert
good articles:
https://www.zhihu.com/question/21711083
https://zh.wikipedia.org/wiki/IEEE_754