Float numbers accuracy

This should not work?
Why is the test being triggered?
arduino nano 33 BLE rev 2.
ide 1.8.19

float y = 0;
void setup() {
Serial.begin(9600);
}

void loop() {
y=0.8;
if (y>0.8) {
Serial.println(y);
}
}

Because 0.8 can't be exactly represented in a finite number of bits to the right of the binary point ... just like 1/7 can't exactly represented by a finite number of digits to the right of the decimal point.

Did you print y with 6 or 7 digits before doing the test? Your code actually gives the expected result on AVR based boards.

float y = 0;
void setup()
{
  Serial.begin(9600);
  while (!Serial) {}
}

void loop()
{
  y = 0.8;
  Serial.println(y, 6);
  if (y > 0.8)
  {
    Serial.println(y);
  }

  delay(1000);
}

Notes:

  1. Please use code tags as described in https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum/679966#posting-code-and-common-code-problems when posting code.
  2. You accidentally made the beginning fo your post a heading; to prevent that when using ----- is to add an additional empty line before the dashes.

This is the output from your code:
0.800000
0.80
0.800000
0.80
0.800000
0.80
0.800000
0.80
0.800000

yes but however it stores 0.8 it should be comparing like with like?
the variable containing 0.8 with the constant 0.8 in the test

the constant 0.8 is being represetned as a double, while the y is type float.

there are more bits in the double, hence the values are exactly the same

You are comparing a float (y) to a double (0.8). Neither is exactly 0.8, but slightly above. The double is closer and thus smaller.

if (y > 0.8f)

compares a float to a float.

The actual float and double values not quite equal to 0.8 are

float  0.800000011920928955078125
double 0.8000000000000000444089209850062616169452667236328125

There are some handy website where you can explore the values stored in float (single) or double. e.g. Decimal to Floating-Point Converter - Exploring Binary

In general, any floating point representation is inexact wrt decimal representation, and you need to account for that when using them. e.g Float is not suitable for currency values, where you want exact decimal representation.

What is it that makes 0.8 a double ?

Floating point literals without a suffix are double.
12.34 - double
12.34f of 12.34F - float
12.34l or 12.34L - long double

With that code, the compiler will most likely do the comparison at compile-time and hard-code the result of the if statement.

Which Arduino board are you using? With an UNO, compiling with Arduino IDE 1.8.19, the code is printing as expected (the if statement is false). < edit > Ah, I see that I am apparently blind.

It is in big letters in post #1...

Read right past that part.

That would be compiling as a 32-bit board and default to double.

Perhaps the compiler should give a warning when comparing different types as the result can vary between different boards.

GCC option -Wdouble-promotion does that (not included in -Wall -Wextra).

aa.cpp: In function ‘void loop()’:
aa.cpp:23:9: warning: implicit conversion from ‘float’ to ‘double’ to match other operand of binary expression [-Wdouble-promotion]
   23 |   if (y > 0.8)
      |       ~~^~~~~