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

UnityPrintFVA uses doubles even if UNITY_EXCLUDE_DOUBLE=1 #592

Open
jonathangjertsen opened this issue Jan 11, 2022 · 2 comments
Open

UnityPrintFVA uses doubles even if UNITY_EXCLUDE_DOUBLE=1 #592

jonathangjertsen opened this issue Jan 11, 2022 · 2 comments

Comments

@jonathangjertsen
Copy link
Contributor

TI's compiler has an option called --float_operations_allowed=32 which will make it refuse to compile code using double point floats. Very useful to avoid accidentally adding several kilobytes to the binary by writing sin instead of sinf for example, or 3.14 instead of 3.14f.

Building Unity with this option set causes the following error due to https://github.com/ThrowTheSwitch/Unity/blob/master/src/unity.c#L1666

line 1666 (col. 46): error #1558-D: 64-bit floating point operations are not allowed

This is the only such case.

There's not a great solution to this because it's impossible to avoid promoting floats to doubles when calling a variadic function.

My suggestion:

#ifndef UNITY_EXCLUDE_FLOAT_PRINT
+#ifndef UNITY_EXCLUDE_DOUBLE
                        case 'f':
                        case 'g':
                            {
                                const double number = va_arg(va, double);
                                UnityPrintFloat((UNITY_DOUBLE)number);
                                break;
                            }
+#endif
#endif

Would this be OK?

@jonathangjertsen
Copy link
Contributor Author

Note that neither UNITY_INCLUDE_PRINT_FORMATTED=0 or UNITY_EXCLUDE_FLOAT_PRINT=1 are satisfactory since that would disable other useful and working features.

@AJIOB
Copy link
Contributor

AJIOB commented Nov 30, 2022

@jonathangjertsen

Looks like you can define UNITY_EXCLUDE_DOUBLE - and UnityPrintFloat call will force use 32-bit floats.

Maybe you can close issue, if that is correct behaviour.

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

No branches or pull requests

2 participants