Skip to content

Fixed point support - #154

Closed
richardhozak wants to merge 5 commits into
dimforge:masterfrom
richardhozak:fixed-point-support
Closed

Fixed point support#154
richardhozak wants to merge 5 commits into
dimforge:masterfrom
richardhozak:fixed-point-support

Conversation

@richardhozak

Copy link
Copy Markdown

Hello,

this PR implements new parry crate (parry-i32f32) with fixed point numbers, as a reference fixed point number with 32 bits for integer part and 32 bits for decimal part was used (FixedI32F32) from simba crate.

There was some missing functionality in simba, that was needed and is implemented in separate PR in simba repository here dimforge/simba#48

This PR is separated into few commits with different meanings:

  • Add fixed point support
    • This commit adds real! macro for constructing f32, f64 and FixedI32F32 literals, this is used for all literals throughout the crate, this is needed as Rust does not have custom literals that can be used for fixed point numbers
  • Use feature flags properly, so rust can find functions for fixed point numbers
    • Tries to resolve few ambiguities, warnings and missing includes between implementations for FixedI32F32 and floats
  • Use conversion functions for converting reals
    • There were some as conversions between floats and integer numbers which do not work for FixedI32F32 and lowest common denominator needs to be used that works both for floats and FixedI32F32, so I used conversion functions
    • as operator uses narrowing conversion, I replaced it with functions that use checked conversions which panic if source cannot be converted to destination, is this ok? I have not found any problems with this yet
    • This is not pretty and I would like suggestions how to do this one better

There are still some tests that do not pass, as fixed point is not as accurate as floats, in parry I found undocumented improved_fixed_point_support cfg feature which when enabled fixes some of these tests, so I left it on, but these tests still fail:

  • test mass_properties::mass_properties::test::mass_properties_add_partial_zero
  • test mass_properties::mass_properties::test::mass_properties_add_sub

Could anyone point me in the right direction so I can fix these tests and what is the preferred solution for f32/f64/FixedI32F32 <-> Integer conversions?

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