This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] CCS/MSP430FR5994:编译器是四舍五入浮点值、无需询问

Guru**** 2580945 points


请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/msp-low-power-microcontrollers-group/msp430/f/msp-low-power-microcontroller-forum/924828/ccs-msp430fr5994-compiler-is-rounding-float-value-unasked

器件型号:MSP430FR5994

工具/软件:Code Composer Studio

您好!

我尝试编写一个函数、根据数据记录器的测量值绘制曲线图。  

内存是一个持久阵列。 LOGADDRESS 是当前的存储位置。

#pragma PERSISTENT (LOGMEM)
#pragma PERSISTENT (LOGADDRESS)
uint16_t LOGEM[75000]={0};
uint32_t LOGADDRESS = 0; 

以下函数应绘制从 LOGEM[0]到 LOGEM[LOGADDRESS]的图表。

不幸的是、行 宽因子= 351/LOGADDRESS;始终生成没有小数部分的浮点(例如351/144 = 2.0)

void showHistory (void)
{
uint32_t i;
volatile uint16_t lastX、lastY、currX、咖喱;

/*
*面积196 * 351像素
*偏移左32像素
*前16像素偏移
*

// const uint16_t areaWidth = 351;
// const uint16_t areaHeight = 196;
const uint8_t offsLeft = 33;
const uint8_t offsTop = 16;

常量浮点高度因子= 0.003738531673;//区域宽度/最大 AD 增量数量(52427)
静态浮点数因子;

如果(LOGADDRESS >0)
{
widthFactor = 351/LOGADDRESS;
lastX = offsLeft;
lastY = lroundf (heightFactor * LOGMEM[0])+ offsTop;

对于(i=1 <LOGADDRESS; i++)
{
currx = lroundf (widthFactor * I)+ offsLeft;
咖喱= lroundf (heightFactor * LOGMEM[i])+ offsTop;

graphics_drawLine (&g_sContext、lastX、lastY、currX、咖喱);

lastx = currx;
lastY =咖喱;
}

clearScreen();
graphics_drawstring (&G) sContext、(INT8_t *) tmpStr、AUTO_STRING_LENGTH、32、204、 false);
FlushDisplayBuffer();
}
else Graphics_drawStringCenter(&g_sContext,"No Data to display!", Auto_string_length, 200, 120, false );
} 

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    >widthFactor = 351/LOGADDRESS;

    我看不到 LOGADDRESS 的定义、但其用法使其看起来是整数的。 尝试强制执行浮点算术、类似于:

    >widthFactor = 351.0/LOGADDRESS;

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    谢谢!