veltaandrg / JavaExercises

0 stars 0 forks source link

Strange Floating-point values #4

Open RodionGork opened 9 years ago

RodionGork commented 9 years ago

In the last part of exercise #3 you should see that double and float can hold special values. Let us get better acquainted with them:

    double x = 5;
    double y = Math.pow(x, 1000);
    double z = x / y;
    double a = -z;
    boolean f1 = (z == a);
    double invZ = 1 / z;
    double invA = 1 / a;
    boolean f2 = (invZ == invA);
    double queer = z / a;
    boolean f3 = (queer == queer);
    boolean f4 = (queer < queer);

Try with the paper and pencil to write which value will be stored in each variable (in every line) if they are executed sequentially. Then try to compile and run it, and see whether your answers were correct.