maniacbug / StandardCplusplus

Standard C++ for Arduino (port of uClibc++)
588 stars 182 forks source link

Added float, double support to the iostreams library for the AVR. #1

Closed gorilux closed 12 years ago

maniacbug commented 12 years ago

Thanks for this! I had a chance to try it out today. Merged it. Looks good, but I can't get the 8th digit of precision.

This code float fmax = FLT_MAX, fmin = FLT_MIN; cout.precision(8); cout << "Float " << scientific << fmax << endl; cout << "Float " << scientific << fmin << endl;

produces this: Float 3.4028235e+38 Float 1.1754944e-38

should be: Float 3.40282347e+38 Float 1.17549435e-38

gorilux commented 12 years ago

I'll give it a test.

maniacbug commented 12 years ago

Ah, the problem is in dtostre. Right at the top it reads, "if (prec>7) prec = 7;" :P

gorilux commented 12 years ago

nothing we can do... and snprintf is not fully supported. So I guess 7 decimal places precision is the max we can get with iostreams in avr. There is one issue with multiple definition in library that I only managed to solve by adding "-Wl,--allow-multiple-definition". If you include the #include in two different .cpp files, you get a linker error complaining about multiple definition (latest version of winavr).

maniacbug commented 12 years ago

Oh, I could not repro that. I tried just now with two CPP files each #include and each printing floats to std::cout, and no problem. This is with avr-gcc 4.5.3 and 4.6.2.