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

Fixes in System.Convert #1928

Merged
merged 10 commits into from
May 24, 2021
Merged

Fixes in System.Convert #1928

merged 10 commits into from
May 24, 2021

Conversation

edleno2
Copy link
Contributor

@edleno2 edleno2 commented May 24, 2021

Description

Reworked parts of System.Convert native code to reuse more of the logic already there for SUPPORT_ANY_BASE_CONVERSION. Removed use of shared GetIntegerPart since it couldn't handle all of the exception cases for signed integers, instead put the code into the NativeToInt64 so it could do all exception checking and handle signed and unsigned values. In NativeToDouble added call to Pow to take 10 to a power since that is more accurate - the original code would be a little faster, but had significant offset from the IEEE 574 standard for generation of double into a 64bit address (ex: min and max values were off from the standard). Code now passes with the standard values.

In nanoprint.c added comments regarding the algorithm used for converting floating numbers and the range of numbers that it can process. Also added "signed" to char cast operation - in win32 a char is treated as signed, but not in GCC. Added "signed" attribute to get the same test results in all platforms.

Motivation and Context

How Has This Been Tested?

Ran NFUnitTestConversions using the nanoFramework Test Framework on Win32, STM32F429I-Discovery, and ESP32-WROOM-32. All tests are passing.

Screenshots

Types of changes

  • Improvement (non-breaking change that improves a feature, code or algorithm)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Config and build (change in the configuration and build system, has no impact on code or features)
  • Dependencies (update dependencies and changes associated, has no impact on code or features)
  • Unit Tests (work on Unit Tests, has no impact on code or features)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

edleno2 and others added 4 commits May 19, 2021 15:22
Removed call to GetIntegerPart since it couldn't support UInt64 conversions and edit for invalid values.  Wrote new string parse loop based on code that is being used for SUPPORT_ANY_BASE_CONVERSION.  Moved some code so it could be used by both SUPPORT_ANY... and the radix 10/16 logic.

Possible problem change in Double parsing - used pow() method to better generate the IEEE 574 compliant double in storage.  pow() is considered to be slow, but without a more precise float multiplication the resulting double will not match what is used by the Roslyn compiler when creating and comparing doubles.

Fixes #715
Cleaned up brackets in system convert to be consistent with rest of file.  Added "signed" to char for cast operation - win32 treats char as signed, but gcc does not.  Adding signed makes this un-ambiguous.

Fix #715
Automated fixes for code style.
@nfbot
Copy link
Member

nfbot commented May 24, 2021

@edleno2 there are issues with the code style on the source files.
A PR was submitted with the code style fixes. Please click https://github.com/edleno2/nf-interpreter/pull/1, review the changes if you want and merge it.

Make sure to follow the project code style. Check the details here on how it works and the tools required to help you with that.

@josesimoes
Copy link
Member

I've fixed the code style in the original code file so that only the real changes show up in your file. Please pull these.

@josesimoes
Copy link
Member

These changes are OK but the code separation with the ifdef for supporting all base conversions needs to be kept where it is, otherwise it's purpose is lost and the smaller targets wont build because of the math code are added.

Please refractor to keep that one there. It's OK to move declarations around, of course.

…c0f-9575-4847-8842-0c97899413f7

Code style fixes for nanoframework/nf-interpreter PR#1928
@josesimoes
Copy link
Member

@edleno2 in case you've missed it, there are conflicts after the merge from the code style fix.

edleno2 added 4 commits May 24, 2021 11:17
Unit tests of boxing/unboxing are expecting invalid cast exception.  Code was returning generic System.Exception with HR of CLR_E_WRONG_TYPE.  Changed code since invalid cast exception is more descriptive of the problem.
@edleno2
Copy link
Contributor Author

edleno2 commented May 24, 2021

@josesimoes
(Please hold this while I retest - just wanted to get past all of the merge conflicts. )

I intentionally moved logic that was in the ifndef to be shared for both with/without SUPPORT_ANY_BASE_CONVERSION. For example, checking for min/max is now done for both cases, and some string operations to set up for negative results is moved ahead of the if/else-defined so it applies to both. Tested on win32 with both conditions to make sure the code work.

@josesimoes
Copy link
Member

@edleno2 your intention is perfectly clear! 😃

What you need to make sure (as you add changes) is that only the absolute math API (from CRT) is pulled in for the targets that support only partial conversion. This is because we have to make sure that each image has the smallest possible code size. (that's the intention of the SUPPORT_ANY_BASE_CONVERSION option: support all or partial conversions).

@edleno2
Copy link
Contributor Author

edleno2 commented May 24, 2021

@josesimoes - completed all of the testing. Ran with and without SUPPORT_ANY_BASE_CONVERSION on win32 and made sure both code interpretations got the expected results, and that no extra math API are being included. Also built firmware on stm32f429 and confirmed that all tests passed on that platform (it is a SUPPORT_ANY_BASE_CONVERSION platform).

Copy link
Member

@josesimoes josesimoes left a comment

Choose a reason for hiding this comment

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

LGTM! Well done. Thanks. 💯

@josesimoes josesimoes changed the title Fix unit tests for conversion of unit types (NFUnitTestConversions) in CoreLibrary Fixes in System.Convert May 24, 2021
@josesimoes josesimoes merged commit 49a8956 into nanoframework:develop May 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NFUnitTestConversions.UnitTestConvertTests.Convert are failing
3 participants