Skip to content

Float fixes#9972

Open
MrSoup678 wants to merge 3 commits intoFacepunch:masterfrom
MrSoup678:float_fixes
Open

Float fixes#9972
MrSoup678 wants to merge 3 commits intoFacepunch:masterfrom
MrSoup678:float_fixes

Conversation

@MrSoup678
Copy link

Pull Request

Thanks for contributing to s&box ❤️
Please fill out the sections below to help us review your change efficiently.


Summary

Fixes float parsing being dependant on culture/locale. The partial handling of this was already present, but Facepunch forgot some of these.

Motivation & Context

Fixes: N/A

Implementation Details

N/A

Screenshots / Videos (if applicable)

Checklist

  • Code follows existing style and conventions
  • No unnecessary formatting or unrelated changes
  • Public APIs are documented (if applicable)
  • Unit tests added where applicable and all passing
  • I’m okay with this PR being rejected or requested to change 🙂

Copilot AI review requested due to automatic review settings February 4, 2026 19:55
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR makes float parsing and serialization culture-invariant in several core math and serialization utilities, and cleans up a few encoding/typographical issues in comments and third-party headers.

Changes:

  • Standardizes string and float conversions in Sandbox.System to use CultureInfo.InvariantCulture or FormattableString.Invariant, covering translation utilities, serialized properties, and RangedFloat.
  • Updates vector/rotation/angles Parse methods to use invariant culture to match other math types and parsing utilities.
  • Fixes mis-encoded characters and punctuation in comments and copyright headers, and clarifies simplification method summaries.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
engine/Sandbox.Test.Unit/UI/Styles/StyleSetting.cs Fixes an apostrophe encoding issue in a CSS transition unit test comment.
engine/Sandbox.System/Translation.cs Makes string conversions and float parsing invariant-culture, aligning translation/conversion behavior with culture-independent expectations.
engine/Sandbox.System/SerializedObject/SerializedProperty.cs Uses invariant culture when converting arbitrary values to strings in serialized properties.
engine/Sandbox.System/Math/Vector4.cs Updates Vector4.Parse/TryParse default path to use invariant culture, matching other math types’ parsing behavior.
engine/Sandbox.System/Math/Rotation.cs Routes default Rotation.Parse/TryParse calls through invariant-culture parsing for consistent numeric handling.
engine/Sandbox.System/Math/RangedFloat.cs Uses invariant culture for parsing optional floats and for ToString, ensuring round-trippable, culture-independent range serialization.
engine/Sandbox.System/Math/Angles.cs Updates Angles.Parse/TryParse default behavior to use invariant culture, consistent with other math parsing helpers and tests.
engine/Sandbox.System/Html/TextNode.cs Fixes a mis-encoded copyright symbol in the Html Agility Pack–derived header comment.
engine/Sandbox.System/Html/ParseErrorCode.cs Same header copyright encoding fix for the Html Agility Pack–derived enum file.
engine/Sandbox.System/Html/ParseError.cs Same header copyright encoding fix for the Html Agility Pack–derived parse error class.
engine/Sandbox.System/Html/NodeType.cs Same header copyright encoding fix for the Html Agility Pack–derived node type enum.
engine/Sandbox.System/Html/Node.cs Same header copyright encoding fix for the Html Agility Pack–derived node class.
engine/Sandbox.System/Html/Document.cs Same header copyright encoding fix for the Html Agility Pack–derived document class.
engine/Sandbox.Engine/Resources/Model/Model.PhysicsBodyBuilder.cs Replaces mis-encoded dashes in SimplifyMethod XML doc comments with standard hyphens for readability and consistency.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

if ( targetType == typeof( float ) )
{
if ( float.TryParse( from.ToString(), out var f ) )
if ( float.TryParse( from.ToString(), CultureInfo.InvariantCulture, out var f ) )
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

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

Here we’re using the float.TryParse(string, IFormatProvider, out float) overload, whereas the rest of the codebase generally uses the explicit NumberStyles.Float + provider overload for culture‑invariant float parsing (for example, Math/Length.cs and Utility/Parse.cs). For consistency with existing parsing behavior and to avoid any subtle differences in accepted formats, consider switching this to the float.TryParse(string, NumberStyles.Float, CultureInfo.InvariantCulture, out var f) pattern used elsewhere.

Suggested change
if ( float.TryParse( from.ToString(), CultureInfo.InvariantCulture, out var f ) )
if ( float.TryParse( from.ToString(), NumberStyles.Float, CultureInfo.InvariantCulture, out var f ) )

Copilot uses AI. Check for mistakes.
Copy link
Member

@handsomematt handsomematt left a comment

Choose a reason for hiding this comment

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

These are good changes, but you've touched and committed so many irrelevent files.

@MrSoup678
Copy link
Author

Looks like dotnet format touches them. It apparently changes encoding of these files from windows-1252 to windows-1250. In what encoding these should be saved anyway?

@MrSoup678 MrSoup678 reopened this Feb 10, 2026
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