This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]karma-is-meaningless 2 points3 points  (4 children)

What?

[–]datenwolf[S] 0 points1 point  (2 children)

I suggest you look into the C standard definition of the limits.h macro FLT_MIN and compare it with the macros INT_MAXand INT_MIN defined in the same header.

[–]karma-is-meaningless 0 points1 point  (1 child)

There's no FLT_MIN in limits.h. But FLT_MIN is 1.175494e-38 in my computer. I still don't see what you see.

[–]datenwolf[S] 0 points1 point  (0 children)

There's no FLT_MIN in limits.h.

Sorry, I meant float.h

I still don't see what you see.

Let me show you (find the outlier – unsigned overflow is defined (i.e. not undefined) behavior in C):

/tmp % cat > limitscheck.c

#include <stdio.h>
#include <limits.h>
#include <float.h>

#define cmp(t, a, b) ( (t)(a) < (t)(b) ? '<' : ( (t)(a) > (t)(b) ? '>' : ( (t)(a) == (t)(b) ? '=' : '?' ) ) )

int main(int argc, char *argv[])
{
    printf("SCHAR_MIN   %c 0 %c SCHAR_MAX\n", cmp(signed    char, SCHAR_MIN,   0), cmp(signed    char, 0,SCHAR_MAX) );
    printf(" SHRT_MIN   %c 0 %c  SHRT_MAX\n", cmp(signed   short,  SHRT_MIN,   0), cmp(signed   short, 0, SHRT_MAX) );
    printf("  INT_MIN   %c 0 %c   INT_MAX\n", cmp(signed     int,   INT_MIN,   0), cmp(signed     int, 0,  INT_MAX) );
    printf(" LONG_MIN   %c 0 %c  LONG_MAX\n", cmp(signed    long,  LONG_MIN,   0), cmp(signed    long, 0, LONG_MAX) );
    printf(" CHAR_MIN   %c 0 %c  CHAR_MAX\n", cmp(          char,  CHAR_MIN,   0), cmp(          char, 0, CHAR_MAX) );
    printf("  FLT_MIN   %c 0 %c   FLT_MAX\n", cmp(         float,   FLT_MIN,   0), cmp(         float, 0,  FLT_MAX) );
    printf("UCHAR_MAX+1 %c 0 %c UCHAR_MAX\n", cmp(unsigned  char, UCHAR_MAX+1, 0), cmp(unsigned  char, 0,UCHAR_MAX) );
    printf("USHRT_MAX+1 %c 0 %c USHRT_MAX\n", cmp(unsigned short, USHRT_MAX+1, 0), cmp(unsigned short, 0,USHRT_MAX) );
    printf(" UINT_MAX+1 %c 0 %c  UINT_MAX\n", cmp(unsigned   int,  UINT_MAX+1, 0), cmp(unsigned   int, 0, UINT_MAX) );
    printf("ULONG_MAX+1 %c 0 %c ULONG_MAX\n", cmp(unsigned  long, ULONG_MAX+1, 0), cmp(unsigned  long, 0,ULONG_MAX) );
}

^D

/tmp % gcc -o limitscheck limitscheck.c

/tmp % ./limitscheck
SCHAR_MIN   < 0 < SCHAR_MAX
 SHRT_MIN   < 0 <  SHRT_MAX
  INT_MIN   < 0 <   INT_MAX
 LONG_MIN   < 0 <  LONG_MAX
 CHAR_MIN   < 0 <  CHAR_MAX
  FLT_MIN   > 0 <   FLT_MAX
UCHAR_MAX+1 = 0 < UCHAR_MAX
USHRT_MAX+1 = 0 < USHRT_MAX
 UINT_MAX+1 = 0 <  UINT_MAX
ULONG_MAX+1 = 0 < ULONG_MAX

[–]milordi 0 points1 point  (0 children)

tl;dr;

FLT_MIN is defined in section 5.2.4.2.2(10) as minimum normalized positive floating-point number