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 is double? that is, the LONG_MIN variable is in the limit of the .h file. what type of 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);

as for float and double? how does min compute this variable? sorry bad english

+3
source share
4 answers

In linux, I have float.h for which FLT_MAX and DBL_MAX are defined for the maximum value of float and double, respectively. I am not sure if this is a "standard" though ...

+8
source

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

+14
source

, , :

float:% f

long float (double):% lf

:% E

min/max float double

float.h:

#define DBL_MAX 1.7976931348623158e+308 /* max value */
#define DBL_MIN 2.2250738585072014e-308 /* min positive value */

#define FLT_MAX 3.402823466e+38F /* max value */
#define FLT_MIN 1.175494351e-38F /* min positive value */
0

, (2^(sizeof(type) * 8)) - 1, (2^number_of_bits) - 1.

Then, if you think that this type should be signed, the minimum and maximum values -2^(number_of_bits - 1)and (2^(number_of_bits - 1)) - 1, or if they are not defined, MIN will be 0 and MAX (2^number_of_bits) - 1.

This applies only to integer types, therefore not for float and double, and then only for two-component Two Complement views.

-1
source

Source: https://habr.com/ru/post/1787536/


All Articles