A constant of type 1. has a double type in both C ++ and C.
C
6.4.4.2/4: An unsuffixed floating constant has type double . If suffixed by letter for F , it has type float . If suffixed by letter or L , it has type long double .
C ++
2.14.4 / 1: It is not possible to explicitly specify the type of suffix.
The compiler used on ideone.com is version 5.1.1 20150711 . So it may make sense to drive it locally, if anyone has the opportunity. A similar compiler on goodbolt (5.1) gives an error with the correct types :
error: invalid operands of types 'double' and 'double' to binary 'operator%' error: in evaluation of 'operator%=(double, double)'
A possible reason is the FLT_EVAL_METHOD value, which sets the calculation accuracy for internal operations. For ideone, this value is 2 , because 32-bit compiler is used :
For gcc, FLT_EVAL_METHOD == 2 is the default on 32 bit x86
Those. All floating point calculations are based on the type long double .
Although, in truth, this should not affect the type of a real constant.
As it turned out, the g ++ compiler can change the value of FLT_EVAL_METHOD from 0 to 2 to 64 bit by adding the -mfpmath=387 key:
#include <stdio.h> #include <float.h> int main() { // 1 % 1.; printf( "%d\n", FLT_EVAL_METHOD); }
Result:
2
In this case, the error message for the second argument also displays the type long double as well as the initial one on ideone (for 32 bit):
invalid operands to binary % (have 'int' and 'long double')
For clang, another key is needed: -mno-sse . In this case, the diagnostic message for both types displays a double :
invalid operands to binary expression ('double' and 'double')
At the same time, the first, as it seems to me, should nevertheless remain an int .
Summarizing, we can say that both compilers in diagnostic messages have problems with the derivation of the original type of operands.
1.- justdouble. In this - it is necessary to dig a standard. Apparently the compiler is naughty . - αλεχολυτdouble. So that was along double, you need a suffix -1.L- Harry