Last active
February 11, 2020 11:50
-
-
Save katsuyoshi/ac77a025e9cd62b483968f20c0bc46bd to your computer and use it in GitHub Desktop.
M5Stackで整数20200211をfloatの変数に代入すると20200212になってしまう
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <M5Stack.h> | |
| float gps_date = 0; | |
| // the setup routine runs once when M5Stack starts up | |
| void setup(){ | |
| // Initialize the M5Stack object | |
| M5.begin(); | |
| /* | |
| Power chip connected to gpio21, gpio22, I2C device | |
| Set battery charging voltage and current | |
| If used battery, please call this function in your project | |
| */ | |
| // LCD display | |
| M5.Lcd.print("Hello World"); | |
| gps_date = 20200210; | |
| Serial.print("gps_date = 20200210; // "); | |
| Serial.println(gps_date); | |
| gps_date += 1.0; | |
| Serial.print("gps_date += 1.0; // "); | |
| Serial.println(gps_date); | |
| gps_date = 20200211; | |
| Serial.print("gps_date = 20200211; // "); | |
| Serial.println(gps_date); | |
| gps_date -= 1.0; | |
| Serial.print("gps_date -= 1.0; // "); | |
| Serial.println(gps_date); | |
| gps_date = 20200212; | |
| Serial.print("gps_date = 20200212; // "); | |
| Serial.println(gps_date); | |
| gps_date = 20200211.1; | |
| Serial.print("gps_date = 20200211.1; // "); | |
| Serial.println(gps_date); | |
| double dv = 20200211; | |
| gps_date = dv; | |
| Serial.print("double dv = 20200211; gps_date = dv; // "); | |
| Serial.println(gps_date); | |
| } | |
| // the loop routine runs over and over again forever | |
| void loop() { | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| gps_date = 20200210; // 20200210.00 | |
| gps_date += 1.0; // 20200212.00 | |
| gps_date = 20200211; // 20200212.00 | |
| gps_date -= 1.0; // 20200212.00 | |
| gps_date = 20200212; // 20200212.00 | |
| gps_date = 20200211.1; // 20200212.00 | |
| double dv = 20200211; gps_date = dv; // 20200212.00 |
Author
Author
結局floatの有効桁数不足という事でバグではありませんでした。orz
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
1を足したり引いたりしてもダメで、一旦doubleに代入してからgps_dateに代入でもダメ。
gps_dateをdoubleで宣言した場合は問題ない。