+ 14
is it log, or using size_t that is the error?
https://code.sololearn.com/cA99GlPl4PCd/?ref=app
+ 11
yes, it seems the compiler is implicitly converting the floating point/double type returned by log to integer.
Maybe there is something in here that can explain this behaviour:
http://www.learncpp.com/cpp-tutorial/44-implicit-type-conversion-coercion/
http://en.cppreference.com/w/cpp/language/implicit_conversion
+ 11
nice! well, I guess we should be aware that not all compilers are created equal
+ 11
It's C++ 17. You can check the version using the __cpluscplus macro: 201703 is the value corresponding to C++ 17: https://code.sololearn.com/ckHSMY7tWjP4/?ref=app
+ 9
how about
size_t N = float(log(64)) / float(log(4));
or
size_t N = log(64.0) / log(4.0);
+ 9
Have you lodged a bug report?
+ 9
It should return a double or float, but the template I suggested was a possible way to enforce that is was doing so.
Prototype(s) for c+11 are: (plural)
double log (double x);
float log (float x);
long double log (long double x);
double log (T x);
http://www.cplusplus.com/reference/cmath/log/
+ 9
I assure you, they do read them.
+ 9
;) Are we discussing schematics now :), we could change the float conversion to a double conversion. I am not saying this is a fix, it's a work around. I agree there is a problem that needs addressing.
As far as I am aware gcc 4.8.1 supports c++11, so yeah. there is a bug somewhere
+ 9
lol, not even a work around, the behaviour still occurs even after forcing the double via a template. So yeah, bug problems in the assignment operation or something.
+ 9
:) I would say you are correct! (narrowing) It would be nice if the compiler had warnings enabled, it would probably allow us to further debug this
+ 8
yeah, I know.. but it's a work around until it actually is updated
template<typename T> float log(T num) { return float(std::log(num));}
Maybe?
+ 8
I would lodge a bug report regarding this, as it would lend more support for a case for upgrading the compiler.
+ 7
I updated the code I used above if you want to see. It seems it is definitely in the assignment operation.
+ 6
Hey guys,
Seems like the compiler got updated! Check it out, your code samples work normally.
- 1
i think i see one error on the code in the challenges:
#include <iostream>
#define func (x) x*x
using namespace std;
cout <<func (5+2)
THE Answer is supose to be: 17
but THE Answer on THE question is another