{"id":17947568,"url":"https://github.com/mrdav30/fixedmathsharp","last_synced_at":"2026-04-02T22:14:06.464Z","repository":{"id":259222265,"uuid":"877075181","full_name":"mrdav30/FixedMathSharp","owner":"mrdav30","description":"FixedMathSharp: A high-precision, deterministic fixed-point math library for .NET. Ideal for simulations, games, and physics engines requiring reliable arithmetic without floating-point inaccuracies.","archived":false,"fork":false,"pushed_at":"2025-03-11T05:08:24.000Z","size":488,"stargazers_count":8,"open_issues_count":1,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-30T17:23:54.905Z","etag":null,"topics":["arithmetic","deterministic","dotnet","fixed-point-arithmetic","game-development","high-precision","math","math-library","physics-engine","simulation","trigonometry","unity"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mrdav30.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-23T03:30:41.000Z","updated_at":"2025-03-18T07:00:50.000Z","dependencies_parsed_at":"2024-10-23T16:55:12.374Z","dependency_job_id":"25be8327-1cfb-4e15-8c2b-3928e1d6015a","html_url":"https://github.com/mrdav30/FixedMathSharp","commit_stats":{"total_commits":12,"total_committers":1,"mean_commits":12.0,"dds":0.0,"last_synced_commit":"38442c5feaa097990c67b590fef5487ba2469376"},"previous_names":["mrdav30/fixedmathsharp"],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrdav30%2FFixedMathSharp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrdav30%2FFixedMathSharp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrdav30%2FFixedMathSharp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrdav30%2FFixedMathSharp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mrdav30","download_url":"https://codeload.github.com/mrdav30/FixedMathSharp/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251731247,"owners_count":21634542,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["arithmetic","deterministic","dotnet","fixed-point-arithmetic","game-development","high-precision","math","math-library","physics-engine","simulation","trigonometry","unity"],"created_at":"2024-10-29T08:05:46.524Z","updated_at":"2026-04-02T22:14:06.456Z","avatar_url":"https://github.com/mrdav30.png","language":"C#","readme":"# FixedMathSharp\n\n![FixedMathSharp Icon](https://raw.githubusercontent.com/mrdav30/fixedmathsharp/main/icon.png)\n\n[![.NET CI](https://github.com/mrdav30/FixedMathSharp/actions/workflows/dotnet.yml/badge.svg)](https://github.com/mrdav30/FixedMathSharp/actions/workflows/dotnet.yml)\n[![Coverage](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fmrdav30.github.io%2FFixedMathSharp%2FSummary.json\u0026query=%24.summary.linecoverage\u0026suffix=%25\u0026label=coverage\u0026color=brightgreen)](https://mrdav30.github.io/FixedMathSharp/)\n[![NuGet](https://img.shields.io/nuget/v/FixedMathSharp.svg)](https://www.nuget.org/packages/FixedMathSharp)\n[![NuGet Downloads](https://img.shields.io/nuget/dt/FixedMathSharp.svg)](https://www.nuget.org/packages/FixedMathSharp)\n[![License](https://img.shields.io/github/license/mrdav30/FixedMathSharp.svg)](https://github.com/mrdav30/FixedMathSharp/blob/main/LICENSE)\n[![Frameworks](https://img.shields.io/badge/frameworks-netstandard2.1%20%7C%20net8.0-512BD4.svg)](https://github.com/mrdav30/FixedMathSharp)\n\n**A high-precision, deterministic fixed-point math library for .NET.**  \nIdeal for simulations, games, and physics engines requiring reliable arithmetic without floating-point inaccuracies.\n\n---\n\n## 🛠️ Key Features\n\n- **Deterministic Calculations:** Ensures consistent results across different platforms.\n- **High Precision Arithmetic:** Uses fixed-point math to eliminate floating-point inaccuracies.\n- **Comprehensive Vector Support:** Includes 2D and 3D vector operations (`Vector2d`, `Vector3d`).\n- **Quaternion Rotations:** Leverage `FixedQuaternion` for smooth rotations without gimbal lock.\n- **Matrix Operations:** Supports transformations with `Fixed4x4` and `Fixed3x3` matrices.\n- **Bounding Shapes:** Includes `IBound` structs `BoundingBox`, `BoundingSphere`, and `BoundingArea` for lightweight spatial calculations.\n- **Advanced Math Functions:** Includes trigonometry and common math utilities.\n- **Framework Agnostic:** Works with **.NET, Unity, and other game engines**.\n- **Full Serialization Support:** Out-of-the-box round-trip serialization via `MemoryPack` across all serializable structs, with `System.Text.Json` constructor support on .NET 8+.\n\n---\n\n## 🚀 Installation\n\nClone the repository and add it to your project:\n\n### Non-Unity Projects\n\n1. **Install via NuGet**:\n   - Add FixedMathSharp to your project using the following command:\n\n     ```bash\n     dotnet add package FixedMathSharp\n     ```\n\n   - If you're using `FluentAssertions` in your test project, the companion assertions package is available here:\n     [FixedMathSharp.FluentAssertions](https://www.nuget.org/packages/FixedMathSharp.FluentAssertions)\n\n2. **Or Download/Clone**:\n   - Clone the repository or download the source code.\n\n     ```bash\n     git clone https://github.com/mrdav30/FixedMathSharp.git\n     ```\n\n3. **Add to Project**:\n\n   - Include the FixedMathSharp project or its DLLs in your build process.\n\n### Unity Integration\n\nFixedMathSharp is now maintained as a separate Unity package.For Unity-specific implementations, refer to:\n\n🔗 [FixedMathSharp-Unity Repository](https://github.com/mrdav30/FixedMathSharp-Unity).\n\n---\n\n## 📖 Usage Examples\n\n### Basic Arithmetic with `Fixed64`\n\n```csharp\nFixed64 a = new Fixed64(1.5);\nFixed64 b = new Fixed64(2.5);\nFixed64 result = a + b;\nConsole.WriteLine(result); // Output: 4.0\n```\n\n### Vector Operations\n\n```csharp\nVector3d v1 = new Vector3d(1, 2, 3);\nVector3d v2 = new Vector3d(4, 5, 6);\nFixed64 dotProduct = Vector3d.Dot(v1, v2);\nConsole.WriteLine(dotProduct); // Output: 32\n```\n\n### Quaternion Rotation\n\n```csharp\nFixedQuaternion rotation = FixedQuaternion.FromAxisAngle(Vector3d.Up, FixedMath.PiOver2); // 90 degrees around Y-axis\nVector3d point = new Vector3d(1, 0, 0);\nVector3d rotatedPoint = rotation.Rotate(point);\nConsole.WriteLine(rotatedPoint); // Output: (0, 0, -1)\n```\n\n### Matrix Transformations\n\n```csharp\nFixed4x4 matrix = Fixed4x4.Identity;\nVector3d position = new Vector3d(1, 2, 3);\nmatrix.SetTransform(position, Vector3d.One, FixedQuaternion.Identity);\nConsole.WriteLine(matrix);\n```\n\n### Bounding Shapes and Intersection\n\n```csharp\nBoundingBox box = new BoundingBox(new Vector3d(0, 0, 0), new Vector3d(5, 5, 5));\nBoundingSphere sphere = new BoundingSphere(new Vector3d(3, 3, 3), new Fixed64(1));\nbool intersects = box.Intersects(sphere);\nConsole.WriteLine(intersects); // Output: True\n```\n\n### Trigonometry Example\n\n```csharp\nFixed64 angle = FixedMath.PiOver4; // 45 degrees\nFixed64 sinValue = FixedTrigonometry.Sin(angle);\nConsole.WriteLine(sinValue); // Output: ~0.707\n```\n\n### Deterministic Random Generation\n\nUse `DeterministicRandom` when you need reproducible random values across runs, worlds, or features.  \nStreams are derived from a seed and remain deterministic regardless of threading or platform.\n\n```csharp\n// Simple constructor-based stream:\nvar rng = new DeterministicRandom(42UL);\n\n// Deterministic integer:\nint value = rng.Next(1, 10); // [1,10)\n\n// Deterministic Fixed64 in [0,1):\nFixed64 ratio = rng.NextFixed6401();\n\n// One stream per “feature” that’s stable for the same worldSeed + key:\nvar rngOre = DeterministicRandom.FromWorldFeature(worldSeed: 123456789UL, featureKey: 0xORE);\nvar rngRivers = DeterministicRandom.FromWorldFeature(123456789UL, 0xRIV, index: 0);\n\n// Deterministic Fixed64 draws:\nFixed64 h = rngOre.NextFixed64(Fixed64.One);                      // [0, 1)\nFixed64 size = rngOre.NextFixed64(Fixed64.Zero, 5 * Fixed64.One); // [0, 5)\nFixed64 posX = rngRivers.NextFixed64(-Fixed64.One, Fixed64.One);  // [-1, 1)\n\n// Deterministic integers:\nint loot = rngOre.Next(1, 5); // [1,5)\n```\n\n---\n\n## 📦 Library Structure\n\n- **`Fixed64` Struct:** Represents fixed-point numbers for precise arithmetic.\n- **`Vector2d` and `Vector3d` Structs:** Handle 2D and 3D vector operations.\n- **`FixedQuaternion` Struct:** Provides rotation handling without gimbal lock, enabling smooth rotations and quaternion-based transformations.\n- **`IBound` Interface:** Standard interface for bounding shapes `BoundingBox`, `BoundingArea`, and `BoundingSphere`, each offering intersection, containment, and projection logic.\n- **`FixedMath` Static Class:** Provides common math and trigonometric functions using fixed-point math.\n- **`Fixed4x4` and `Fixed3x3`:** Support matrix operations for transformations.\n- **`DeterministicRandom` Struct:** Seedable, allocation-free RNG for repeatable procedural generation.  \n\n### Fixed64 Struct\n\n**Fixed64** is the core data type representing fixed-point numbers. It provides various mathematical operations, including addition, subtraction, multiplication, division, and more.\nThe struct guarantees deterministic behavior by using integer-based arithmetic with a configurable `SHIFT_AMOUNT`.\n\n---\n\n## ⚡ Performance Considerations\n\nFixedMathSharp is optimized for high-performance deterministic calculations:\n\n- **Inline methods and bit-shifting optimizations** ensure minimal overhead.\n- **Eliminates floating-point drift**, making it ideal for lockstep simulations.\n- **Supports fuzzy equality comparisons** for handling minor precision deviations.\n\n---\n\n## 🧪 Testing and Validation\n\nUnit tests are used extensively to validate the correctness of mathematical operations.\nSpecial **fuzzy comparisons** are employed where small precision discrepancies might occur, mimicking floating-point behavior.\n\nTo run the tests:\n\n```bash\ndotnet test --configuration debug\n```\n\n---\n\n## 🛠️ Compatibility\n\n- **.NET Standard** 2.1\n- **.NET** 8\n- **Unity 2020+** (via [FixedMathSharp-Unity](https://github.com/mrdav30/FixedMathSharp-Unity))\n- **Cross-Platform Support** (Windows, Linux, macOS)\n\n---\n\n## 🤝 Contributing\n\nWe welcome contributions! Please see our [CONTRIBUTING](https://github.com/mrdav30/FixedMathSharp/blob/main/CONTRIBUTING.md) guide for details on how to propose changes, report issues, and interact with the community.\n\n---\n\n## 👥 Contributors\n\n- **mrdav30** - Lead Developer\n- Contributions are welcome! Feel free to submit pull requests or report issues.\n\n---\n\n## 💬 Community \u0026 Support\n\nFor questions, discussions, or general support, join the official Discord community:\n\n👉 **[Join the Discord Server](https://discord.gg/mhwK2QFNBA)**\n\nFor bug reports or feature requests, please open an issue in this repository.\n\nWe welcome feedback, contributors, and community discussion across all projects.\n\n---\n\n## License\n\nThis project is licensed under the MIT License.\n\nSee the following files for details:\n\n- LICENSE – standard MIT license\n- NOTICE – additional terms regarding project branding and redistribution\n- COPYRIGHT – authorship information\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrdav30%2Ffixedmathsharp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmrdav30%2Ffixedmathsharp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrdav30%2Ffixedmathsharp/lists"}