Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Describe fixed-point types #26

Merged
merged 1 commit into from
Aug 3, 2024
Merged

Describe fixed-point types #26

merged 1 commit into from
Aug 3, 2024

Conversation

jouae
Copy link
Collaborator

@jouae jouae commented Jul 29, 2024

Describing the type using only the 12.4, 24.8, or 2.6 format is unclear for reading and doesn't clearly indicate
how many bits are used for the integer and fractional parts.

Add a brief explanation to clarify the meaning of the numbers before and after the decimal point.

The number before the decimal point represents how many bits are used for the integer part, and the number after the decimal point represents how many bits are used for the fractional part.

include/twin_private.h Outdated Show resolved Hide resolved
@jouae
Copy link
Collaborator Author

jouae commented Jul 29, 2024

In the CI environment, clang-format-18 is used for formatting, but the .clang-format settings in the main directory differ from those of clang-format-18. Which format should be considered the primary one?

After I applied .clang-format -i src/twin_private.h

+#define twin_int_div(a, b) (((uint16_t) (a) *255) / (b))
-#define twin_int_div(a, b) (((uint16_t) (a) * 255) / (b))

but in CI environment,

-#define twin_int_div(a, b) (((uint16_t) (a) *255) / (b))
+#define twin_int_div(a, b) (((uint16_t) (a) * 255) / (b))

@jserv
Copy link
Contributor

jserv commented Jul 29, 2024

After I applied .clang-format -i ./src/twin_private.h

+#define twin_int_div(a, b) (((uint16_t) (a) *255) / (b))
-#define twin_int_div(a, b) (((uint16_t) (a) * 255) / (b))

Make sure clang-format-18 is properly installed. See https://apt.llvm.org/

@jserv jserv changed the title Add descripition of fixed-point type Describe fixed-point types Jul 29, 2024
Copy link
Contributor

@jserv jserv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix typo in the subject "Add descripition of fixed-point type"

include/twin_private.h Outdated Show resolved Hide resolved
Copy link
Contributor

@jserv jserv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use git rebase rather than git merge.

include/twin_private.h Outdated Show resolved Hide resolved
In the original comment, the fixed-point type was only
explained using 12.4 and 24.8, lacking details about
the number of bits allocated for the integer, fractional,
and sign parts.

Here, following the supplementary content for C99 in
'section 6.3.6.3 fixed-point types' of the ISO/IEC TR 18037:2008,
additional descriptions of these fixed-point types are provided.

In particular:
In a fixed-point type where
N bits are used to represent the value, with
L bits allocated for the integer part, the remaining
N−L bits are used for the fractional part.
The actual value range of this fixed-point type is from -2^L to 2^{L}-2^{N-L}.

Additionally, a table is provided showing hexadecimal, decimal, binary,
and actual values to help developers quickly understand
the value range of this fixed-point type.

Refs:
	1. ISO/IEC TR 18037:2008
	   4.2 Detailed changes to ISO/IEC 9899:1999
@jouae
Copy link
Collaborator Author

jouae commented Aug 3, 2024

Do we need to consider compatibility with one's complement?

@jserv
Copy link
Contributor

jserv commented Aug 3, 2024

Do we need to consider compatibility with one's complement?

No.

@jserv jserv merged commit 3ff36b9 into sysprog21:main Aug 3, 2024
3 checks passed
@jserv
Copy link
Contributor

jserv commented Aug 3, 2024

Thank @jouae for contributing!

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.

2 participants