Floating-Point Round-off Errors - C Data Type

C examples for Data Type:float

Introduction

Take a number, add 1 to it, and subtract the original number.

A floating-point calculation may give another answer:

Demo Code

#include <stdio.h>
int main(void)
{
    float a,b;/* w  ww .  j a  v  a  2  s.c om*/
    
    b = 2.0e20 + 1.0;
    a = b - 2.0e20;

    printf("%f \n", a);
    
    return 0;
}

Result


Related Tutorials