Skip to content

Instantly share code, notes, and snippets.

@katsuyoshi
Last active February 11, 2020 11:50
Show Gist options
  • Select an option

  • Save katsuyoshi/ac77a025e9cd62b483968f20c0bc46bd to your computer and use it in GitHub Desktop.

Select an option

Save katsuyoshi/ac77a025e9cd62b483968f20c0bc46bd to your computer and use it in GitHub Desktop.
M5Stackで整数20200211をfloatの変数に代入すると20200212になってしまう
#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() {
}
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
@katsuyoshi
Copy link
Author

1を足したり引いたりしてもダメで、一旦doubleに代入してからgps_dateに代入でもダメ。
gps_dateをdoubleで宣言した場合は問題ない。

@katsuyoshi
Copy link
Author

結局floatの有効桁数不足という事でバグではありませんでした。orz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment