Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#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;
}
@noname007

This comment has been minimized.

Copy link
Owner Author

@noname007 noname007 commented Oct 18, 2018

> (= 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
@noname007

This comment has been minimized.

Copy link
Owner Author

@noname007 noname007 commented Oct 18, 2018

<?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

@noname007

This comment has been minimized.

Copy link
Owner Author

@noname007 noname007 commented Oct 19, 2018

from abaove zhihu link

image

image

@noname007

This comment has been minimized.

Copy link
Owner Author

@noname007 noname007 commented Oct 19, 2018

问题:

  • 浮点数能表示的最大数,(非正无穷) 是个整数,还是个浮点数
  • 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);
@noname007

This comment has been minimized.

Copy link
Owner Author

@noname007 noname007 commented Oct 19, 2018

@noname007

This comment has been minimized.

Copy link
Owner Author

@noname007 noname007 commented Dec 17, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.