FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix potential undefined behavior in sin/cos by dekutree64 · Pull Request #524 · simplefoc/Arduino-FOC · GitHub

Fix potential undefined behavior in sin/cos - #524

Open
dekutree64 wants to merge 2 commits into
simplefoc:devfrom
dekutree64:dev
Open

Fix potential undefined behavior in sin/cos#524
dekutree64 wants to merge 2 commits into
simplefoc:devfrom
dekutree64:dev

Conversation

Copy link
Copy Markdown
Contributor

Description

Fixes #505 (cast from float to unsigned int not guaranteed to work on all platforms)

When testing, I also discovered that it may not work on platforms with 16-bit int. On PC, casting from float to short (signed 16-bit integer) will saturate to -32768 if the float value is outside of the -32768 to 32767 range, rather than truncating the upper bits. So the initial conversion is now to 32-bit int, then truncate to whatever is fastest for the platform you're on.
Type of change

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Max error and RMS error verified unchanged on PC. Tested running a motor in open loop mode on STM32.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant


Back | FazBrowse Home | New Git URL