Example sketches for the new Arduino IDE for ESP8266

Moderator: igrr

User avatar
By picstart
#41260 Mathematics is notational. In decimal notation there are often two forms integer and fixed point. Most often fixed point is represented by binary normalized floating point to some finite precision for the mantissa and the exponent in the MCU. Integer is represented as binary to some precision. In mathematics all power series of two that can be represented within the precision will be notationally equivalent to the decimal integer representation. This is not true for say 1/3 in binary this can't be represented within any precision. The difference in results to decimal calculations is often called a rounding error but is really just a natural mathematical consequence of changing a number base from decimal to binary and back again. The c compiler is doing the correct mathematics. If the MCU used base 3 instead of base 2 then 1/3 could be represented precisely.
User avatar
By xtal
#41281 I've found that RFH =8 then RFH/3600= value then serial.print(value,4) prints 0.0000

However 3600/RFH = value the 1/value then serial.print(value,4) prints 0.0022

Arduino 1.6.5 2.1.0-RC2
User avatar
By xtal
#41378 SOLVED
If both operands are integer, the result of a division will also be an integer in C/C++ (rounded down to the next int).
You need to make at least one operand a float value (either by adding .0f if it's a constant or casting to float).


Thanks lethe
This makes some since....