Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Limits for floating point types?

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

int main(void){
        printf("Type                Size      Min                 Max\n----------------------------------------------------------------------\n");
        printf("%-20s%-10d%-20ld%-20ld\n", "long", sizeof(long), LONG_MIN, LONG_MAX);
        printf("%-20s%-10d%-20lu%-20lu\n", "unsigned long", sizeof(long), 0, ULONG_MAX);
        return 0;
}

where double? i.e. variable LONG_MIN be in file limits.h. in which type double?

   int i, min, max;

    for (i = 1.0; i > 0; ++i)
    {
        max = i;
    };
    min = i;
    printf ("int: min: %d max: %d \n", min, max);

how do for float and double? how min calculated this variable? sorry bad english

like image 440
ferz Avatar asked Jan 24 '11 20:01

ferz


People also ask

What are the limitations of floating-point representation?

Floating-point numbers suffer from a loss of precision when represented with a fixed number of bits (e.g., 32-bit or 64-bit). This is because there is an infinite amount of real numbers, even within a small range like 0.0 to 0.1.

Does float have a limit?

A floating point number does not "reserve space" for the digits after the decimal point - it has a limited number of digits (23 binary) and remembers what power of two to multiply it by.


2 Answers

The limits for floating point types are defined in float.h not limits.h

like image 97
Clifford Avatar answered Nov 09 '22 08:11

Clifford


on linux, I have float.h which has FLT_MAX and DBL_MAX defined for maximum float and double values respectively. I'm not sure how "standard" that is, though...

like image 21
vmpstr Avatar answered Nov 09 '22 09:11

vmpstr