From 484959f30f44bd31824f61be8c92c380469b5fd8 Mon Sep 17 00:00:00 2001
From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com>
Date: Wed, 6 Sep 2023 22:10:13 -0500
Subject: [PATCH 001/293] Initial commit
---
.editorconfig | 160 +++++++++
.gitattributes | 2 +
.gitignore | 398 +++++++++++++++++++++
LICENSE | 21 ++
Mathematics.NET.sln | 25 ++
src/Mathematics.NET/Mathematics.NET.csproj | 9 +
6 files changed, 615 insertions(+)
create mode 100644 .editorconfig
create mode 100644 .gitattributes
create mode 100644 .gitignore
create mode 100644 LICENSE
create mode 100644 Mathematics.NET.sln
create mode 100644 src/Mathematics.NET/Mathematics.NET.csproj
diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 00000000..0aeaf666
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,160 @@
+### General ###
+[*]
+
+file_header_template = \nMathematics.NET\nhttps://github.com/HamletTanyavong/Mathematics.NET\n\nMIT License\n\nCopyright (c) 2023 Hamlet Tanyavong\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the "Software"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n
+
+indent_style = space
+trim_trailing_whitespace = true
+insert_final_newline = true
+
+### Json files ###
+[*.json]
+
+indent_size = 2
+
+### Xml files ###
+[*.xml]
+
+indent_size = 2
+
+### Http files ###
+[*.http]
+
+indent_size = 2
+
+### C# ###
+[*.cs]
+
+# Naming rules
+
+dotnet_naming_rule.private_or_internal_static_field_should_be_s_with_underscore.severity = suggestion
+dotnet_naming_rule.private_or_internal_static_field_should_be_s_with_underscore.symbols = private_or_internal_static_field
+dotnet_naming_rule.private_or_internal_static_field_should_be_s_with_underscore.style = s_with_underscore
+
+dotnet_naming_rule.private_or_internal_field_should_be_underscore.severity = suggestion
+dotnet_naming_rule.private_or_internal_field_should_be_underscore.symbols = private_or_internal_field
+dotnet_naming_rule.private_or_internal_field_should_be_underscore.style = underscore
+
+# Symbol specifications
+
+dotnet_naming_symbols.private_or_internal_static_field.applicable_kinds = field
+dotnet_naming_symbols.private_or_internal_static_field.applicable_accessibilities = internal, private, private_protected
+dotnet_naming_symbols.private_or_internal_static_field.required_modifiers = static
+
+dotnet_naming_symbols.private_or_internal_field.applicable_kinds = field
+dotnet_naming_symbols.private_or_internal_field.applicable_accessibilities = internal, private, private_protected
+dotnet_naming_symbols.private_or_internal_field.required_modifiers =
+
+# Naming styles
+
+dotnet_naming_style.s_with_underscore.required_prefix = s_
+dotnet_naming_style.s_with_underscore.required_suffix =
+dotnet_naming_style.s_with_underscore.word_separator =
+dotnet_naming_style.s_with_underscore.capitalization = camel_case
+
+dotnet_naming_style.underscore.required_prefix = _
+dotnet_naming_style.underscore.required_suffix =
+dotnet_naming_style.underscore.word_separator =
+dotnet_naming_style.underscore.capitalization = camel_case
+csharp_indent_labels = one_less_than_current
+csharp_using_directive_placement = outside_namespace:silent
+csharp_prefer_simple_using_statement = true:suggestion
+csharp_prefer_braces = true:silent
+csharp_style_namespace_declarations = file_scoped:silent
+csharp_style_prefer_method_group_conversion = true:silent
+csharp_style_prefer_top_level_statements = true:silent
+csharp_style_expression_bodied_methods = when_on_single_line:silent
+csharp_style_expression_bodied_constructors = false:silent
+csharp_style_expression_bodied_operators = when_on_single_line:silent
+csharp_style_expression_bodied_properties = when_on_single_line:silent
+csharp_style_expression_bodied_indexers = when_on_single_line:silent
+csharp_style_expression_bodied_accessors = when_on_single_line:silent
+csharp_style_expression_bodied_lambdas = when_on_single_line:silent
+csharp_style_expression_bodied_local_functions = when_on_single_line:silent
+csharp_style_throw_expression = true:suggestion
+csharp_style_prefer_null_check_over_type_check = true:suggestion
+csharp_prefer_simple_default_expression = true:suggestion
+csharp_style_prefer_local_over_anonymous_function = true:suggestion
+csharp_style_prefer_index_operator = true:suggestion
+csharp_style_prefer_range_operator = true:suggestion
+csharp_style_implicit_object_creation_when_type_is_apparent = true:suggestion
+csharp_style_prefer_tuple_swap = true:suggestion
+csharp_space_around_binary_operators = before_and_after
+
+# C# and Visual Basic
+[*.{cs,vb}]
+
+# Naming rules
+
+dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion
+dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface
+dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i
+
+dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion
+dotnet_naming_rule.types_should_be_pascal_case.symbols = types
+dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case
+
+dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion
+dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members
+dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case
+
+# Symbol specifications
+
+dotnet_naming_symbols.interface.applicable_kinds = interface
+dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
+dotnet_naming_symbols.interface.required_modifiers =
+
+dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
+dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
+dotnet_naming_symbols.types.required_modifiers =
+
+dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
+dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
+dotnet_naming_symbols.non_field_members.required_modifiers =
+
+# Naming styles
+
+dotnet_naming_style.begins_with_i.required_prefix = I
+dotnet_naming_style.begins_with_i.required_suffix =
+dotnet_naming_style.begins_with_i.word_separator =
+dotnet_naming_style.begins_with_i.capitalization = pascal_case
+
+dotnet_naming_style.pascal_case.required_prefix =
+dotnet_naming_style.pascal_case.required_suffix =
+dotnet_naming_style.pascal_case.word_separator =
+dotnet_naming_style.pascal_case.capitalization = pascal_case
+
+dotnet_naming_style.pascal_case.required_prefix =
+dotnet_naming_style.pascal_case.required_suffix =
+dotnet_naming_style.pascal_case.word_separator =
+dotnet_naming_style.pascal_case.capitalization = pascal_case
+dotnet_style_operator_placement_when_wrapping = beginning_of_line
+tab_width = 4
+indent_size = 4
+end_of_line = crlf
+dotnet_style_coalesce_expression = true:suggestion
+dotnet_style_null_propagation = true:suggestion
+dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
+dotnet_style_prefer_auto_properties = true:silent
+dotnet_style_object_initializer = true:suggestion
+dotnet_style_collection_initializer = true:suggestion
+dotnet_style_prefer_simplified_boolean_expressions = true:suggestion
+dotnet_style_prefer_conditional_expression_over_assignment = true:silent
+dotnet_style_prefer_conditional_expression_over_return = true:silent
+dotnet_style_explicit_tuple_names = true:suggestion
+dotnet_style_prefer_inferred_tuple_names = true:suggestion
+dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
+dotnet_style_prefer_compound_assignment = true:suggestion
+dotnet_style_prefer_simplified_interpolation = true:suggestion
+dotnet_style_namespace_match_folder = true:suggestion
+
+# Diagnostics
+
+# Default severity for analyzer diagnostics with category 'Style'
+dotnet_analyzer_diagnostic.category-Style.severity = suggestion
+
+# IDE0073: The file header does not match the required text
+dotnet_diagnostic.IDE0073.severity = warning
+
+# IDE0008: Use explicit type
+dotnet_diagnostic.IDE0008.severity = none
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 00000000..dfe07704
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,2 @@
+# Auto detect text files and perform LF normalization
+* text=auto
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 00000000..426d76dd
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,398 @@
+## Ignore Visual Studio temporary files, build results, and
+## files generated by popular Visual Studio add-ons.
+##
+## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore
+
+# User-specific files
+*.rsuser
+*.suo
+*.user
+*.userosscache
+*.sln.docstates
+
+# User-specific files (MonoDevelop/Xamarin Studio)
+*.userprefs
+
+# Mono auto generated files
+mono_crash.*
+
+# Build results
+[Dd]ebug/
+[Dd]ebugPublic/
+[Rr]elease/
+[Rr]eleases/
+x64/
+x86/
+[Ww][Ii][Nn]32/
+[Aa][Rr][Mm]/
+[Aa][Rr][Mm]64/
+bld/
+[Bb]in/
+[Oo]bj/
+[Ll]og/
+[Ll]ogs/
+
+# Visual Studio 2015/2017 cache/options directory
+.vs/
+# Uncomment if you have tasks that create the project's static files in wwwroot
+#wwwroot/
+
+# Visual Studio 2017 auto generated files
+Generated\ Files/
+
+# MSTest test Results
+[Tt]est[Rr]esult*/
+[Bb]uild[Ll]og.*
+
+# NUnit
+*.VisualState.xml
+TestResult.xml
+nunit-*.xml
+
+# Build Results of an ATL Project
+[Dd]ebugPS/
+[Rr]eleasePS/
+dlldata.c
+
+# Benchmark Results
+BenchmarkDotNet.Artifacts/
+
+# .NET Core
+project.lock.json
+project.fragment.lock.json
+artifacts/
+
+# ASP.NET Scaffolding
+ScaffoldingReadMe.txt
+
+# StyleCop
+StyleCopReport.xml
+
+# Files built by Visual Studio
+*_i.c
+*_p.c
+*_h.h
+*.ilk
+*.meta
+*.obj
+*.iobj
+*.pch
+*.pdb
+*.ipdb
+*.pgc
+*.pgd
+*.rsp
+*.sbr
+*.tlb
+*.tli
+*.tlh
+*.tmp
+*.tmp_proj
+*_wpftmp.csproj
+*.log
+*.tlog
+*.vspscc
+*.vssscc
+.builds
+*.pidb
+*.svclog
+*.scc
+
+# Chutzpah Test files
+_Chutzpah*
+
+# Visual C++ cache files
+ipch/
+*.aps
+*.ncb
+*.opendb
+*.opensdf
+*.sdf
+*.cachefile
+*.VC.db
+*.VC.VC.opendb
+
+# Visual Studio profiler
+*.psess
+*.vsp
+*.vspx
+*.sap
+
+# Visual Studio Trace Files
+*.e2e
+
+# TFS 2012 Local Workspace
+$tf/
+
+# Guidance Automation Toolkit
+*.gpState
+
+# ReSharper is a .NET coding add-in
+_ReSharper*/
+*.[Rr]e[Ss]harper
+*.DotSettings.user
+
+# TeamCity is a build add-in
+_TeamCity*
+
+# DotCover is a Code Coverage Tool
+*.dotCover
+
+# AxoCover is a Code Coverage Tool
+.axoCover/*
+!.axoCover/settings.json
+
+# Coverlet is a free, cross platform Code Coverage Tool
+coverage*.json
+coverage*.xml
+coverage*.info
+
+# Visual Studio code coverage results
+*.coverage
+*.coveragexml
+
+# NCrunch
+_NCrunch_*
+.*crunch*.local.xml
+nCrunchTemp_*
+
+# MightyMoose
+*.mm.*
+AutoTest.Net/
+
+# Web workbench (sass)
+.sass-cache/
+
+# Installshield output folder
+[Ee]xpress/
+
+# DocProject is a documentation generator add-in
+DocProject/buildhelp/
+DocProject/Help/*.HxT
+DocProject/Help/*.HxC
+DocProject/Help/*.hhc
+DocProject/Help/*.hhk
+DocProject/Help/*.hhp
+DocProject/Help/Html2
+DocProject/Help/html
+
+# Click-Once directory
+publish/
+
+# Publish Web Output
+*.[Pp]ublish.xml
+*.azurePubxml
+# Note: Comment the next line if you want to checkin your web deploy settings,
+# but database connection strings (with potential passwords) will be unencrypted
+*.pubxml
+*.publishproj
+
+# Microsoft Azure Web App publish settings. Comment the next line if you want to
+# checkin your Azure Web App publish settings, but sensitive information contained
+# in these scripts will be unencrypted
+PublishScripts/
+
+# NuGet Packages
+*.nupkg
+# NuGet Symbol Packages
+*.snupkg
+# The packages folder can be ignored because of Package Restore
+**/[Pp]ackages/*
+# except build/, which is used as an MSBuild target.
+!**/[Pp]ackages/build/
+# Uncomment if necessary however generally it will be regenerated when needed
+#!**/[Pp]ackages/repositories.config
+# NuGet v3's project.json files produces more ignorable files
+*.nuget.props
+*.nuget.targets
+
+# Microsoft Azure Build Output
+csx/
+*.build.csdef
+
+# Microsoft Azure Emulator
+ecf/
+rcf/
+
+# Windows Store app package directories and files
+AppPackages/
+BundleArtifacts/
+Package.StoreAssociation.xml
+_pkginfo.txt
+*.appx
+*.appxbundle
+*.appxupload
+
+# Visual Studio cache files
+# files ending in .cache can be ignored
+*.[Cc]ache
+# but keep track of directories ending in .cache
+!?*.[Cc]ache/
+
+# Others
+ClientBin/
+~$*
+*~
+*.dbmdl
+*.dbproj.schemaview
+*.jfm
+*.pfx
+*.publishsettings
+orleans.codegen.cs
+
+# Including strong name files can present a security risk
+# (https://github.com/github/gitignore/pull/2483#issue-259490424)
+#*.snk
+
+# Since there are multiple workflows, uncomment next line to ignore bower_components
+# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
+#bower_components/
+
+# RIA/Silverlight projects
+Generated_Code/
+
+# Backup & report files from converting an old project file
+# to a newer Visual Studio version. Backup files are not needed,
+# because we have git ;-)
+_UpgradeReport_Files/
+Backup*/
+UpgradeLog*.XML
+UpgradeLog*.htm
+ServiceFabricBackup/
+*.rptproj.bak
+
+# SQL Server files
+*.mdf
+*.ldf
+*.ndf
+
+# Business Intelligence projects
+*.rdl.data
+*.bim.layout
+*.bim_*.settings
+*.rptproj.rsuser
+*- [Bb]ackup.rdl
+*- [Bb]ackup ([0-9]).rdl
+*- [Bb]ackup ([0-9][0-9]).rdl
+
+# Microsoft Fakes
+FakesAssemblies/
+
+# GhostDoc plugin setting file
+*.GhostDoc.xml
+
+# Node.js Tools for Visual Studio
+.ntvs_analysis.dat
+node_modules/
+
+# Visual Studio 6 build log
+*.plg
+
+# Visual Studio 6 workspace options file
+*.opt
+
+# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
+*.vbw
+
+# Visual Studio 6 auto-generated project file (contains which files were open etc.)
+*.vbp
+
+# Visual Studio 6 workspace and project file (working project files containing files to include in project)
+*.dsw
+*.dsp
+
+# Visual Studio 6 technical files
+*.ncb
+*.aps
+
+# Visual Studio LightSwitch build output
+**/*.HTMLClient/GeneratedArtifacts
+**/*.DesktopClient/GeneratedArtifacts
+**/*.DesktopClient/ModelManifest.xml
+**/*.Server/GeneratedArtifacts
+**/*.Server/ModelManifest.xml
+_Pvt_Extensions
+
+# Paket dependency manager
+.paket/paket.exe
+paket-files/
+
+# FAKE - F# Make
+.fake/
+
+# CodeRush personal settings
+.cr/personal
+
+# Python Tools for Visual Studio (PTVS)
+__pycache__/
+*.pyc
+
+# Cake - Uncomment if you are using it
+# tools/**
+# !tools/packages.config
+
+# Tabs Studio
+*.tss
+
+# Telerik's JustMock configuration file
+*.jmconfig
+
+# BizTalk build output
+*.btp.cs
+*.btm.cs
+*.odx.cs
+*.xsd.cs
+
+# OpenCover UI analysis results
+OpenCover/
+
+# Azure Stream Analytics local run output
+ASALocalRun/
+
+# MSBuild Binary and Structured Log
+*.binlog
+
+# NVidia Nsight GPU debugger configuration file
+*.nvuser
+
+# MFractors (Xamarin productivity tool) working folder
+.mfractor/
+
+# Local History for Visual Studio
+.localhistory/
+
+# Visual Studio History (VSHistory) files
+.vshistory/
+
+# BeatPulse healthcheck temp database
+healthchecksdb
+
+# Backup folder for Package Reference Convert tool in Visual Studio 2017
+MigrationBackup/
+
+# Ionide (cross platform F# VS Code tools) working folder
+.ionide/
+
+# Fody - auto-generated XML schema
+FodyWeavers.xsd
+
+# VS Code files for those working on multiple tools
+.vscode/*
+!.vscode/settings.json
+!.vscode/tasks.json
+!.vscode/launch.json
+!.vscode/extensions.json
+*.code-workspace
+
+# Local History for Visual Studio Code
+.history/
+
+# Windows Installer files from build outputs
+*.cab
+*.msi
+*.msix
+*.msm
+*.msp
+
+# JetBrains Rider
+*.sln.iml
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 00000000..0c64253e
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2023 Hamlet Tanyavong
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/Mathematics.NET.sln b/Mathematics.NET.sln
new file mode 100644
index 00000000..6a24988d
--- /dev/null
+++ b/Mathematics.NET.sln
@@ -0,0 +1,25 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 17
+VisualStudioVersion = 17.7.34024.191
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mathematics.NET", "Mathematics.NET\Mathematics.NET.csproj", "{86370FDB-532F-4C3C-813B-3D1BBFE0B063}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {86370FDB-532F-4C3C-813B-3D1BBFE0B063}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {86370FDB-532F-4C3C-813B-3D1BBFE0B063}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {86370FDB-532F-4C3C-813B-3D1BBFE0B063}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {86370FDB-532F-4C3C-813B-3D1BBFE0B063}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {179D9282-B1D9-42EC-A6A0-C1970012ED73}
+ EndGlobalSection
+EndGlobal
diff --git a/src/Mathematics.NET/Mathematics.NET.csproj b/src/Mathematics.NET/Mathematics.NET.csproj
new file mode 100644
index 00000000..cfadb03d
--- /dev/null
+++ b/src/Mathematics.NET/Mathematics.NET.csproj
@@ -0,0 +1,9 @@
+
+
+
+ net7.0
+ enable
+ enable
+
+
+
From 9c8ad90017e9d2248d9b87e8350905033939073e Mon Sep 17 00:00:00 2001
From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com>
Date: Wed, 6 Sep 2023 23:05:23 -0500
Subject: [PATCH 002/293] Add src folder
- Add src folder to solution and move Mathematics.NET project inside
---
Mathematics.NET.sln | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/Mathematics.NET.sln b/Mathematics.NET.sln
index 6a24988d..fe040a5b 100644
--- a/Mathematics.NET.sln
+++ b/Mathematics.NET.sln
@@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.7.34024.191
MinimumVisualStudioVersion = 10.0.40219.1
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mathematics.NET", "Mathematics.NET\Mathematics.NET.csproj", "{86370FDB-532F-4C3C-813B-3D1BBFE0B063}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mathematics.NET", "src\Mathematics.NET\Mathematics.NET.csproj", "{558EB964-1CE7-4786-9656-6EEC36A7072E}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{DAD16084-D255-4DF4-A20D-077E92B88EC5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -11,14 +13,18 @@ Global
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {86370FDB-532F-4C3C-813B-3D1BBFE0B063}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {86370FDB-532F-4C3C-813B-3D1BBFE0B063}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {86370FDB-532F-4C3C-813B-3D1BBFE0B063}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {86370FDB-532F-4C3C-813B-3D1BBFE0B063}.Release|Any CPU.Build.0 = Release|Any CPU
+ {558EB964-1CE7-4786-9656-6EEC36A7072E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {558EB964-1CE7-4786-9656-6EEC36A7072E}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {558EB964-1CE7-4786-9656-6EEC36A7072E}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {558EB964-1CE7-4786-9656-6EEC36A7072E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
+ GlobalSection(NestedProjects) = preSolution
+ {558EB964-1CE7-4786-9656-6EEC36A7072E} = {DAD16084-D255-4DF4-A20D-077E92B88EC5}
+ {557642D0-685A-4846-AD31-DC764692E853} = {DAD16084-D255-4DF4-A20D-077E92B88EC5}
+ EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {179D9282-B1D9-42EC-A6A0-C1970012ED73}
EndGlobalSection
From 3ebfe6b9820c8b824a20436a0665cd228129231d Mon Sep 17 00:00:00 2001
From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com>
Date: Wed, 6 Sep 2023 23:05:56 -0500
Subject: [PATCH 003/293] Add files to Solution Items folder
- Add .editorconfig, .gitattributes, .gitignore, and LICENSE files to Solution Items folder
---
Mathematics.NET.sln | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/Mathematics.NET.sln b/Mathematics.NET.sln
index fe040a5b..cd95f8b4 100644
--- a/Mathematics.NET.sln
+++ b/Mathematics.NET.sln
@@ -7,6 +7,14 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mathematics.NET", "src\Math
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{DAD16084-D255-4DF4-A20D-077E92B88EC5}"
EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{ADB18351-2BD5-4FA8-921A-09726E7AA6FC}"
+ ProjectSection(SolutionItems) = preProject
+ .editorconfig = .editorconfig
+ .gitattributes = .gitattributes
+ .gitignore = .gitignore
+ LICENSE = LICENSE
+ EndProjectSection
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
From 55218a3468dcc55ff95148e89d95ae67da395d5f Mon Sep 17 00:00:00 2001
From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com>
Date: Wed, 6 Sep 2023 23:06:11 -0500
Subject: [PATCH 004/293] Add tests folder
---
Mathematics.NET.sln | 2 ++
1 file changed, 2 insertions(+)
diff --git a/Mathematics.NET.sln b/Mathematics.NET.sln
index cd95f8b4..84c1abcd 100644
--- a/Mathematics.NET.sln
+++ b/Mathematics.NET.sln
@@ -15,6 +15,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
LICENSE = LICENSE
EndProjectSection
EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{91DB0FE7-BAA4-4D16-8A39-65332DD53662}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
From 8ff41bf7a6b54a344912c8202d164eacddd73762 Mon Sep 17 00:00:00 2001
From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com>
Date: Wed, 6 Sep 2023 23:10:33 -0500
Subject: [PATCH 005/293] Add source generator project
- Fix spacing in Mathematics.NET.csproj
---
Mathematics.NET.sln | 6 ++++++
.../Mathematics.NET.SourceGenerators.csproj | 18 ++++++++++++++++++
src/Mathematics.NET/Mathematics.NET.csproj | 6 +++++-
3 files changed, 29 insertions(+), 1 deletion(-)
create mode 100644 src/Mathematics.NET.SourceGenerators/Mathematics.NET.SourceGenerators.csproj
diff --git a/Mathematics.NET.sln b/Mathematics.NET.sln
index 84c1abcd..ffb2d5cc 100644
--- a/Mathematics.NET.sln
+++ b/Mathematics.NET.sln
@@ -17,6 +17,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{91DB0FE7-BAA4-4D16-8A39-65332DD53662}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mathematics.NET.SourceGenerators", "src\Mathematics.NET.SourceGenerators\Mathematics.NET.SourceGenerators.csproj", "{557642D0-685A-4846-AD31-DC764692E853}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -27,6 +29,10 @@ Global
{558EB964-1CE7-4786-9656-6EEC36A7072E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{558EB964-1CE7-4786-9656-6EEC36A7072E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{558EB964-1CE7-4786-9656-6EEC36A7072E}.Release|Any CPU.Build.0 = Release|Any CPU
+ {557642D0-685A-4846-AD31-DC764692E853}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {557642D0-685A-4846-AD31-DC764692E853}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {557642D0-685A-4846-AD31-DC764692E853}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {557642D0-685A-4846-AD31-DC764692E853}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/src/Mathematics.NET.SourceGenerators/Mathematics.NET.SourceGenerators.csproj b/src/Mathematics.NET.SourceGenerators/Mathematics.NET.SourceGenerators.csproj
new file mode 100644
index 00000000..d70db3ce
--- /dev/null
+++ b/src/Mathematics.NET.SourceGenerators/Mathematics.NET.SourceGenerators.csproj
@@ -0,0 +1,18 @@
+
+
+
+ true
+ false
+ latest
+ netstandard2.0
+
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
+
+
diff --git a/src/Mathematics.NET/Mathematics.NET.csproj b/src/Mathematics.NET/Mathematics.NET.csproj
index cfadb03d..0ad1fa6f 100644
--- a/src/Mathematics.NET/Mathematics.NET.csproj
+++ b/src/Mathematics.NET/Mathematics.NET.csproj
@@ -1,4 +1,4 @@
-
+
net7.0
@@ -6,4 +6,8 @@
enable
+
+
+
+
From 340b3a823649f33940102911fdc2ce0c6b280a96 Mon Sep 17 00:00:00 2001
From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com>
Date: Fri, 8 Sep 2023 15:35:41 -0500
Subject: [PATCH 006/293] Update Mathematics.NET.sln
---
Mathematics.NET.sln | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Mathematics.NET.sln b/Mathematics.NET.sln
index ffb2d5cc..01d116a1 100644
--- a/Mathematics.NET.sln
+++ b/Mathematics.NET.sln
@@ -17,7 +17,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{91DB0FE7-BAA4-4D16-8A39-65332DD53662}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mathematics.NET.SourceGenerators", "src\Mathematics.NET.SourceGenerators\Mathematics.NET.SourceGenerators.csproj", "{557642D0-685A-4846-AD31-DC764692E853}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mathematics.NET.SourceGenerators", "src\Mathematics.NET.SourceGenerators\Mathematics.NET.SourceGenerators.csproj", "{557642D0-685A-4846-AD31-DC764692E853}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
From 026e66ef112bafddf8d9bf057aa995ff2ad441e8 Mon Sep 17 00:00:00 2001
From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com>
Date: Fri, 8 Sep 2023 15:53:31 -0500
Subject: [PATCH 007/293] Target x64
---
Mathematics.NET.sln | 20 +++++++++----------
.../Mathematics.NET.SourceGenerators.csproj | 1 +
src/Mathematics.NET/Mathematics.NET.csproj | 1 +
3 files changed, 12 insertions(+), 10 deletions(-)
diff --git a/Mathematics.NET.sln b/Mathematics.NET.sln
index 01d116a1..b1578b72 100644
--- a/Mathematics.NET.sln
+++ b/Mathematics.NET.sln
@@ -21,18 +21,18 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mathematics.NET.SourceGener
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
- Debug|Any CPU = Debug|Any CPU
- Release|Any CPU = Release|Any CPU
+ Debug|x64 = Debug|x64
+ Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {558EB964-1CE7-4786-9656-6EEC36A7072E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {558EB964-1CE7-4786-9656-6EEC36A7072E}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {558EB964-1CE7-4786-9656-6EEC36A7072E}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {558EB964-1CE7-4786-9656-6EEC36A7072E}.Release|Any CPU.Build.0 = Release|Any CPU
- {557642D0-685A-4846-AD31-DC764692E853}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {557642D0-685A-4846-AD31-DC764692E853}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {557642D0-685A-4846-AD31-DC764692E853}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {557642D0-685A-4846-AD31-DC764692E853}.Release|Any CPU.Build.0 = Release|Any CPU
+ {558EB964-1CE7-4786-9656-6EEC36A7072E}.Debug|x64.ActiveCfg = Debug|x64
+ {558EB964-1CE7-4786-9656-6EEC36A7072E}.Debug|x64.Build.0 = Debug|x64
+ {558EB964-1CE7-4786-9656-6EEC36A7072E}.Release|x64.ActiveCfg = Release|x64
+ {558EB964-1CE7-4786-9656-6EEC36A7072E}.Release|x64.Build.0 = Release|x64
+ {557642D0-685A-4846-AD31-DC764692E853}.Debug|x64.ActiveCfg = Debug|x64
+ {557642D0-685A-4846-AD31-DC764692E853}.Debug|x64.Build.0 = Debug|x64
+ {557642D0-685A-4846-AD31-DC764692E853}.Release|x64.ActiveCfg = Release|x64
+ {557642D0-685A-4846-AD31-DC764692E853}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/src/Mathematics.NET.SourceGenerators/Mathematics.NET.SourceGenerators.csproj b/src/Mathematics.NET.SourceGenerators/Mathematics.NET.SourceGenerators.csproj
index d70db3ce..6a6637e7 100644
--- a/src/Mathematics.NET.SourceGenerators/Mathematics.NET.SourceGenerators.csproj
+++ b/src/Mathematics.NET.SourceGenerators/Mathematics.NET.SourceGenerators.csproj
@@ -5,6 +5,7 @@
false
latest
netstandard2.0
+ x64
diff --git a/src/Mathematics.NET/Mathematics.NET.csproj b/src/Mathematics.NET/Mathematics.NET.csproj
index 0ad1fa6f..e8022477 100644
--- a/src/Mathematics.NET/Mathematics.NET.csproj
+++ b/src/Mathematics.NET/Mathematics.NET.csproj
@@ -4,6 +4,7 @@
net7.0
enable
enable
+ x64
From 56470014448f16f25cc7942ece68d346bb4590a5 Mon Sep 17 00:00:00 2001
From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com>
Date: Fri, 8 Sep 2023 16:00:16 -0500
Subject: [PATCH 008/293] Add console application
- Add console application for help with development
- Add the project folder to .gitignore since the project is only for testing
---
.gitignore | 3 +++
Mathematics.NET.sln | 7 +++++++
2 files changed, 10 insertions(+)
diff --git a/.gitignore b/.gitignore
index 426d76dd..b23fb46a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,6 +3,9 @@
##
## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore
+# Manually-added items
+/src/Application/
+
# User-specific files
*.rsuser
*.suo
diff --git a/Mathematics.NET.sln b/Mathematics.NET.sln
index b1578b72..f0289ad3 100644
--- a/Mathematics.NET.sln
+++ b/Mathematics.NET.sln
@@ -19,6 +19,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{91DB0FE7
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mathematics.NET.SourceGenerators", "src\Mathematics.NET.SourceGenerators\Mathematics.NET.SourceGenerators.csproj", "{557642D0-685A-4846-AD31-DC764692E853}"
EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Application", "src\Application\Application.csproj", "{173526DA-4560-4D64-81EF-5D757A44FBFA}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
@@ -33,6 +35,10 @@ Global
{557642D0-685A-4846-AD31-DC764692E853}.Debug|x64.Build.0 = Debug|x64
{557642D0-685A-4846-AD31-DC764692E853}.Release|x64.ActiveCfg = Release|x64
{557642D0-685A-4846-AD31-DC764692E853}.Release|x64.Build.0 = Release|x64
+ {173526DA-4560-4D64-81EF-5D757A44FBFA}.Debug|x64.ActiveCfg = Debug|x64
+ {173526DA-4560-4D64-81EF-5D757A44FBFA}.Debug|x64.Build.0 = Debug|x64
+ {173526DA-4560-4D64-81EF-5D757A44FBFA}.Release|x64.ActiveCfg = Release|x64
+ {173526DA-4560-4D64-81EF-5D757A44FBFA}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -40,6 +46,7 @@ Global
GlobalSection(NestedProjects) = preSolution
{558EB964-1CE7-4786-9656-6EEC36A7072E} = {DAD16084-D255-4DF4-A20D-077E92B88EC5}
{557642D0-685A-4846-AD31-DC764692E853} = {DAD16084-D255-4DF4-A20D-077E92B88EC5}
+ {173526DA-4560-4D64-81EF-5D757A44FBFA} = {DAD16084-D255-4DF4-A20D-077E92B88EC5}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {179D9282-B1D9-42EC-A6A0-C1970012ED73}
From 199592ea6bc12dcdade276b3cd39eadb7497db36 Mon Sep 17 00:00:00 2001
From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com>
Date: Fri, 8 Sep 2023 16:47:27 -0500
Subject: [PATCH 009/293] Add test project
---
Mathematics.NET.sln | 7 +++++
.../Mathematics.NET.Tests.csproj | 27 +++++++++++++++++++
2 files changed, 34 insertions(+)
create mode 100644 tests/Mathematics.NET.Tests/Mathematics.NET.Tests.csproj
diff --git a/Mathematics.NET.sln b/Mathematics.NET.sln
index f0289ad3..a5b4eeff 100644
--- a/Mathematics.NET.sln
+++ b/Mathematics.NET.sln
@@ -21,6 +21,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mathematics.NET.SourceGener
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Application", "src\Application\Application.csproj", "{173526DA-4560-4D64-81EF-5D757A44FBFA}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mathematics.NET.Tests", "tests\Mathematics.NET.Tests\Mathematics.NET.Tests.csproj", "{A608C0E2-D431-45E9-AD05-A49115BE59AB}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
@@ -39,6 +41,10 @@ Global
{173526DA-4560-4D64-81EF-5D757A44FBFA}.Debug|x64.Build.0 = Debug|x64
{173526DA-4560-4D64-81EF-5D757A44FBFA}.Release|x64.ActiveCfg = Release|x64
{173526DA-4560-4D64-81EF-5D757A44FBFA}.Release|x64.Build.0 = Release|x64
+ {A608C0E2-D431-45E9-AD05-A49115BE59AB}.Debug|x64.ActiveCfg = Debug|x64
+ {A608C0E2-D431-45E9-AD05-A49115BE59AB}.Debug|x64.Build.0 = Debug|x64
+ {A608C0E2-D431-45E9-AD05-A49115BE59AB}.Release|x64.ActiveCfg = Release|x64
+ {A608C0E2-D431-45E9-AD05-A49115BE59AB}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -47,6 +53,7 @@ Global
{558EB964-1CE7-4786-9656-6EEC36A7072E} = {DAD16084-D255-4DF4-A20D-077E92B88EC5}
{557642D0-685A-4846-AD31-DC764692E853} = {DAD16084-D255-4DF4-A20D-077E92B88EC5}
{173526DA-4560-4D64-81EF-5D757A44FBFA} = {DAD16084-D255-4DF4-A20D-077E92B88EC5}
+ {A608C0E2-D431-45E9-AD05-A49115BE59AB} = {91DB0FE7-BAA4-4D16-8A39-65332DD53662}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {179D9282-B1D9-42EC-A6A0-C1970012ED73}
diff --git a/tests/Mathematics.NET.Tests/Mathematics.NET.Tests.csproj b/tests/Mathematics.NET.Tests/Mathematics.NET.Tests.csproj
new file mode 100644
index 00000000..85c84edf
--- /dev/null
+++ b/tests/Mathematics.NET.Tests/Mathematics.NET.Tests.csproj
@@ -0,0 +1,27 @@
+
+
+
+ net7.0
+ enable
+ enable
+
+ false
+ true
+ AnyCPU;x64
+
+
+
+
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
+
+
+
+
+
From 5702a3e34b4b203ee4402a9d115faf523de0fd45 Mon Sep 17 00:00:00 2001
From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com>
Date: Fri, 8 Sep 2023 16:47:53 -0500
Subject: [PATCH 010/293] Ignore .runsettings file
---
.gitignore | 1 +
1 file changed, 1 insertion(+)
diff --git a/.gitignore b/.gitignore
index b23fb46a..7fed5599 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,6 +5,7 @@
# Manually-added items
/src/Application/
+*.runsettings
# User-specific files
*.rsuser
From 666994ccac4b093c92968ebbe06404a6e64a61a0 Mon Sep 17 00:00:00 2001
From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com>
Date: Fri, 8 Sep 2023 22:36:49 -0500
Subject: [PATCH 011/293] Create IAdditionOperation.cs
- Add an interface that defines the addition operation
---
.../Core/Operations/IAdditionOperation.cs | 38 +++++++++++++++++++
1 file changed, 38 insertions(+)
create mode 100644 src/Mathematics.NET/Core/Operations/IAdditionOperation.cs
diff --git a/src/Mathematics.NET/Core/Operations/IAdditionOperation.cs b/src/Mathematics.NET/Core/Operations/IAdditionOperation.cs
new file mode 100644
index 00000000..6493c0bb
--- /dev/null
+++ b/src/Mathematics.NET/Core/Operations/IAdditionOperation.cs
@@ -0,0 +1,38 @@
+//
+// Mathematics.NET
+// https://github.com/HamletTanyavong/Mathematics.NET
+//
+// MIT License
+//
+// Copyright (c) 2023 Hamlet Tanyavong
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in all
+// copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+// SOFTWARE.
+//
+
+namespace Mathematics.NET.Core.Operations;
+
+/// Defines a mechanism for adding two values
+/// The input type
+/// The output type
+public interface IAdditionOperation
+ where TInput : IAdditionOperation
+{
+ static abstract TOutput operator +(TInput left, TInput right);
+ static virtual TOutput operator checked +(TInput left, TInput right) => left + right;
+}
From fa5e203bc050800e167ae968b238c34dc0a8c0fa Mon Sep 17 00:00:00 2001
From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com>
Date: Fri, 8 Sep 2023 22:37:04 -0500
Subject: [PATCH 012/293] Create IMultiplicationOperation.cs
- Add an interface that defines the multiplication operation
---
.../Operations/IMultiplicationOperation.cs | 38 +++++++++++++++++++
1 file changed, 38 insertions(+)
create mode 100644 src/Mathematics.NET/Core/Operations/IMultiplicationOperation.cs
diff --git a/src/Mathematics.NET/Core/Operations/IMultiplicationOperation.cs b/src/Mathematics.NET/Core/Operations/IMultiplicationOperation.cs
new file mode 100644
index 00000000..1aaab338
--- /dev/null
+++ b/src/Mathematics.NET/Core/Operations/IMultiplicationOperation.cs
@@ -0,0 +1,38 @@
+//
+// Mathematics.NET
+// https://github.com/HamletTanyavong/Mathematics.NET
+//
+// MIT License
+//
+// Copyright (c) 2023 Hamlet Tanyavong
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in all
+// copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+// SOFTWARE.
+//
+
+namespace Mathematics.NET.Core.Operations;
+
+/// Defines a mechanism for multiplying two values
+/// The input type
+/// The output type
+public interface IMultiplicationOperation
+ where TInput : IMultiplicationOperation
+{
+ static abstract TOutput operator *(TInput left, TInput right);
+ static virtual TOutput operator checked *(TInput left, TInput right) => left * right;
+}
From f723f2bb9467b852e80cd946d38d167d9ad722da Mon Sep 17 00:00:00 2001
From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com>
Date: Fri, 8 Sep 2023 22:42:43 -0500
Subject: [PATCH 013/293] Create ISubtractionOperation.cs
- Add an interface that defines the subtraction operation
---
.../Core/Operations/ISubtractionOperation.cs | 38 +++++++++++++++++++
1 file changed, 38 insertions(+)
create mode 100644 src/Mathematics.NET/Core/Operations/ISubtractionOperation.cs
diff --git a/src/Mathematics.NET/Core/Operations/ISubtractionOperation.cs b/src/Mathematics.NET/Core/Operations/ISubtractionOperation.cs
new file mode 100644
index 00000000..a76e4c61
--- /dev/null
+++ b/src/Mathematics.NET/Core/Operations/ISubtractionOperation.cs
@@ -0,0 +1,38 @@
+//
+// Mathematics.NET
+// https://github.com/HamletTanyavong/Mathematics.NET
+//
+// MIT License
+//
+// Copyright (c) 2023 Hamlet Tanyavong
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in all
+// copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+// SOFTWARE.
+//
+
+namespace Mathematics.NET.Core.Operations;
+
+/// Defines a mechanism for subtracting two values
+/// The input type
+/// The output type
+public interface ISubtractionOperation
+ where TInput : ISubtractionOperation
+{
+ static abstract TOutput operator -(TInput left, TInput right);
+ static virtual TOutput operator checked -(TInput left, TInput right) => left - right;
+}
From 17d0bef546d19040f7e210750728f0a3edabd15e Mon Sep 17 00:00:00 2001
From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com>
Date: Fri, 8 Sep 2023 22:42:56 -0500
Subject: [PATCH 014/293] Create IDivisionOperation.cs
- Add an interface that defines the division operation
---
.../Core/Operations/IDivisionOperation.cs | 38 +++++++++++++++++++
1 file changed, 38 insertions(+)
create mode 100644 src/Mathematics.NET/Core/Operations/IDivisionOperation.cs
diff --git a/src/Mathematics.NET/Core/Operations/IDivisionOperation.cs b/src/Mathematics.NET/Core/Operations/IDivisionOperation.cs
new file mode 100644
index 00000000..2388458f
--- /dev/null
+++ b/src/Mathematics.NET/Core/Operations/IDivisionOperation.cs
@@ -0,0 +1,38 @@
+//
+// Mathematics.NET
+// https://github.com/HamletTanyavong/Mathematics.NET
+//
+// MIT License
+//
+// Copyright (c) 2023 Hamlet Tanyavong
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in all
+// copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+// SOFTWARE.
+//
+
+namespace Mathematics.NET.Core.Operations;
+
+/// Defines a mechanism for dividing two values
+/// The input type
+/// The output type
+public interface IDivisionOperation
+ where TInput : IDivisionOperation
+{
+ static abstract TOutput operator /(TInput left, TInput right);
+ static virtual TOutput operator checked /(TInput left, TInput right) => left / right;
+}
From 2b6d6299b290bc9c4638b792e811603194fdaa4d Mon Sep 17 00:00:00 2001
From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com>
Date: Sat, 9 Sep 2023 12:01:39 -0500
Subject: [PATCH 015/293] Add project reference
---
tests/Mathematics.NET.Tests/Mathematics.NET.Tests.csproj | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/tests/Mathematics.NET.Tests/Mathematics.NET.Tests.csproj b/tests/Mathematics.NET.Tests/Mathematics.NET.Tests.csproj
index 85c84edf..88d91375 100644
--- a/tests/Mathematics.NET.Tests/Mathematics.NET.Tests.csproj
+++ b/tests/Mathematics.NET.Tests/Mathematics.NET.Tests.csproj
@@ -20,6 +20,10 @@
+
+
+
+
From 0efd1067ccf1c3dce419fe11636fc5a6fb0ee2bf Mon Sep 17 00:00:00 2001
From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com>
Date: Sat, 9 Sep 2023 12:01:51 -0500
Subject: [PATCH 016/293] Add global using
---
tests/Mathematics.NET.Tests/Mathematics.NET.Tests.csproj | 1 +
1 file changed, 1 insertion(+)
diff --git a/tests/Mathematics.NET.Tests/Mathematics.NET.Tests.csproj b/tests/Mathematics.NET.Tests/Mathematics.NET.Tests.csproj
index 88d91375..320c6e6e 100644
--- a/tests/Mathematics.NET.Tests/Mathematics.NET.Tests.csproj
+++ b/tests/Mathematics.NET.Tests/Mathematics.NET.Tests.csproj
@@ -25,6 +25,7 @@
+
From beb8fe7a6e100ee0fc1d80496be3d7bd352fb53b Mon Sep 17 00:00:00 2001
From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com>
Date: Sat, 9 Sep 2023 12:02:42 -0500
Subject: [PATCH 017/293] Add class for testing complex numbers
- Add tests for complex conjugation
---
.../Core/ComplexNumberTests.cs | 57 +++++++++++++++++++
1 file changed, 57 insertions(+)
create mode 100644 tests/Mathematics.NET.Tests/Core/ComplexNumberTests.cs
diff --git a/tests/Mathematics.NET.Tests/Core/ComplexNumberTests.cs b/tests/Mathematics.NET.Tests/Core/ComplexNumberTests.cs
new file mode 100644
index 00000000..dc736bdd
--- /dev/null
+++ b/tests/Mathematics.NET.Tests/Core/ComplexNumberTests.cs
@@ -0,0 +1,57 @@
+//
+// Mathematics.NET
+// https://github.com/HamletTanyavong/Mathematics.NET
+//
+// MIT License
+//
+// Copyright (c) 2023 Hamlet Tanyavong
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in all
+// copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+// SOFTWARE.
+//
+
+namespace Mathematics.NET.Tests.Core;
+
+[TestClass]
+[TestCategory("Core"), TestCategory("Complex Number")]
+public sealed class ComplexNumberTests
+{
+ [TestMethod]
+ [DataRow(1, 2, 1, -2)]
+ public void Conjugate_ComplexNumberOfInt32_ReturnsConjugate(int inReal, int inImaginary, int outReal, int outImaginary)
+ {
+ ComplexNumber input = new(inReal, inImaginary);
+ ComplexNumber expected = new(outReal, outImaginary);
+
+ var actual = ComplexNumber.Conjugate(input);
+
+ Assert.AreEqual(expected, actual);
+ }
+
+ [TestMethod]
+ [DataRow(1.2, 2.3, 1.2, -2.3)]
+ public void Conjugate_ComplexNumberOfDouble_ReturnsConjugate(double inReal, double inImaginary, double outReal, double outImaginary)
+ {
+ ComplexNumber input = new(inReal, inImaginary);
+ ComplexNumber expected = new(outReal, outImaginary);
+
+ var actual = ComplexNumber.Conjugate(input);
+
+ Assert.AreEqual(expected, actual);
+ }
+}
From b9b8706ce1ebf75caa981a99c9ec77beaa01c222 Mon Sep 17 00:00:00 2001
From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com>
Date: Sun, 10 Sep 2023 13:09:25 -0500
Subject: [PATCH 018/293] Create Precision.cs
- Add machine epsilons for float and double
---
src/Mathematics.NET/Core/Precision.cs | 46 +++++++++++++++++++++++++++
1 file changed, 46 insertions(+)
create mode 100644 src/Mathematics.NET/Core/Precision.cs
diff --git a/src/Mathematics.NET/Core/Precision.cs b/src/Mathematics.NET/Core/Precision.cs
new file mode 100644
index 00000000..294bfa83
--- /dev/null
+++ b/src/Mathematics.NET/Core/Precision.cs
@@ -0,0 +1,46 @@
+//
+// Mathematics.NET
+// https://github.com/HamletTanyavong/Mathematics.NET
+//
+// MIT License
+//
+// Copyright (c) 2023 Hamlet Tanyavong
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in all
+// copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+// SOFTWARE.
+//
+
+using System.Numerics;
+
+namespace Mathematics.NET.Core;
+
+/// A class for working with floating-point numbers
+public static class Precision
+{
+ /// Machine epsilon for single-precision floating-point numbers according to the formal definition
+ public const double FltEpsilonFormal = 5.96046447753906250e-8;
+
+ /// Machine epsilon for double-precision floating-point numbers according to the formal definition
+ public const double DblEpsilonFormal = 1.11022302462515654e-16;
+
+ /// Machine epsilon for single-precision floating-point numbers according to the variant definition
+ public const double FltEpsilonVariant = 1.19209289550781250e-7;
+
+ /// Machine epsilon for double-precision floating-point numbers according to the variant definition
+ public const double DblEpsilonVariant = 2.22044604925031308e-16;
+}
From 76142417eb9302111b06c048af0a052c992bbe90 Mon Sep 17 00:00:00 2001
From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com>
Date: Mon, 11 Sep 2023 11:55:25 -0500
Subject: [PATCH 019/293] Create IComplex.cs
- Add interface defining support for complex numbers
---
src/Mathematics.NET/Core/IComplex.cs | 42 ++++++++++++++++++++++++++++
1 file changed, 42 insertions(+)
create mode 100644 src/Mathematics.NET/Core/IComplex.cs
diff --git a/src/Mathematics.NET/Core/IComplex.cs b/src/Mathematics.NET/Core/IComplex.cs
new file mode 100644
index 00000000..0797d998
--- /dev/null
+++ b/src/Mathematics.NET/Core/IComplex.cs
@@ -0,0 +1,42 @@
+//
+// Mathematics.NET
+// https://github.com/HamletTanyavong/Mathematics.NET
+//
+// MIT License
+//
+// Copyright (c) 2023 Hamlet Tanyavong
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in all
+// copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+// SOFTWARE.
+//
+
+using System.Numerics;
+using Mathematics.NET.Core.Operations;
+
+namespace Mathematics.NET.Core;
+
+/// Defines support for complex numbers
+/// The type that implements the interface
+/// A type that implements
+public interface IComplex
+ where T : IComplex
+ where U : INumber
+{
+ public U Real { get; }
+ public virtual U Imaginary => U.Zero;
+}
From 929b832309cf23ea650b5324f1cc707bc521fb82 Mon Sep 17 00:00:00 2001
From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com>
Date: Mon, 11 Sep 2023 11:57:52 -0500
Subject: [PATCH 020/293] Create ComplexNumber.cs
- Implement IComplex interface
---
src/Mathematics.NET/Core/ComplexNumber.cs | 46 +++++++++++++++++++++++
1 file changed, 46 insertions(+)
create mode 100644 src/Mathematics.NET/Core/ComplexNumber.cs
diff --git a/src/Mathematics.NET/Core/ComplexNumber.cs b/src/Mathematics.NET/Core/ComplexNumber.cs
new file mode 100644
index 00000000..9962d378
--- /dev/null
+++ b/src/Mathematics.NET/Core/ComplexNumber.cs
@@ -0,0 +1,46 @@
+//
+// Mathematics.NET
+// https://github.com/HamletTanyavong/Mathematics.NET
+//
+// MIT License
+//
+// Copyright (c) 2023 Hamlet Tanyavong
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in all
+// copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+// SOFTWARE.
+//
+
+using System.Numerics;
+
+namespace Mathematics.NET.Core;
+
+public readonly struct ComplexNumber : IComplex, T>
+ where T : INumber
+{
+ private readonly T _real;
+ private readonly T _imaginary;
+
+ public ComplexNumber(T real, T imaginary)
+ {
+ _real = real;
+ _imaginary = imaginary;
+ }
+
+ public T Real => _real;
+ public T Imaginary => _imaginary;
+}
From 57c3fe834efb39d79862eb9eadf764f68eb17fd7 Mon Sep 17 00:00:00 2001
From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com>
Date: Mon, 11 Sep 2023 12:00:39 -0500
Subject: [PATCH 021/293] Rename ComplexNumber to Complex
- Update test class to match change
---
.../Core/{ComplexNumber.cs => Complex.cs} | 6 +++---
...{ComplexNumberTests.cs => ComplexTests.cs} | 20 +++++++++----------
2 files changed, 13 insertions(+), 13 deletions(-)
rename src/Mathematics.NET/Core/{ComplexNumber.cs => Complex.cs} (89%)
rename tests/Mathematics.NET.Tests/Core/{ComplexNumberTests.cs => ComplexTests.cs} (67%)
diff --git a/src/Mathematics.NET/Core/ComplexNumber.cs b/src/Mathematics.NET/Core/Complex.cs
similarity index 89%
rename from src/Mathematics.NET/Core/ComplexNumber.cs
rename to src/Mathematics.NET/Core/Complex.cs
index 9962d378..8eea3147 100644
--- a/src/Mathematics.NET/Core/ComplexNumber.cs
+++ b/src/Mathematics.NET/Core/Complex.cs
@@ -1,4 +1,4 @@
-//
+//
// Mathematics.NET
// https://github.com/HamletTanyavong/Mathematics.NET
//
@@ -29,13 +29,13 @@
namespace Mathematics.NET.Core;
-public readonly struct ComplexNumber : IComplex, T>
+public readonly struct Complex : IComplex, T>
where T : INumber
{
private readonly T _real;
private readonly T _imaginary;
- public ComplexNumber(T real, T imaginary)
+ public Complex(T real, T imaginary)
{
_real = real;
_imaginary = imaginary;
diff --git a/tests/Mathematics.NET.Tests/Core/ComplexNumberTests.cs b/tests/Mathematics.NET.Tests/Core/ComplexTests.cs
similarity index 67%
rename from tests/Mathematics.NET.Tests/Core/ComplexNumberTests.cs
rename to tests/Mathematics.NET.Tests/Core/ComplexTests.cs
index dc736bdd..a78c592f 100644
--- a/tests/Mathematics.NET.Tests/Core/ComplexNumberTests.cs
+++ b/tests/Mathematics.NET.Tests/Core/ComplexTests.cs
@@ -1,4 +1,4 @@
-//
+//
// Mathematics.NET
// https://github.com/HamletTanyavong/Mathematics.NET
//
@@ -29,28 +29,28 @@ namespace Mathematics.NET.Tests.Core;
[TestClass]
[TestCategory("Core"), TestCategory("Complex Number")]
-public sealed class ComplexNumberTests
+public sealed class ComplexTests
{
[TestMethod]
[DataRow(1, 2, 1, -2)]
- public void Conjugate_ComplexNumberOfInt32_ReturnsConjugate(int inReal, int inImaginary, int outReal, int outImaginary)
+ public void Conjugate_ComplexOfInt32_ReturnsConjugate(int inReal, int inImaginary, int outReal, int outImaginary)
{
- ComplexNumber input = new(inReal, inImaginary);
- ComplexNumber expected = new(outReal, outImaginary);
+ Complex input = new(inReal, inImaginary);
+ Complex expected = new(outReal, outImaginary);
- var actual = ComplexNumber.Conjugate(input);
+ var actual = Complex.Conjugate(input);
Assert.AreEqual(expected, actual);
}
[TestMethod]
[DataRow(1.2, 2.3, 1.2, -2.3)]
- public void Conjugate_ComplexNumberOfDouble_ReturnsConjugate(double inReal, double inImaginary, double outReal, double outImaginary)
+ public void Conjugate_ComplexOfDouble_ReturnsConjugate(double inReal, double inImaginary, double outReal, double outImaginary)
{
- ComplexNumber input = new(inReal, inImaginary);
- ComplexNumber expected = new(outReal, outImaginary);
+ Complex input = new(inReal, inImaginary);
+ Complex expected = new(outReal, outImaginary);
- var actual = ComplexNumber.Conjugate(input);
+ var actual = Complex.Conjugate(input);
Assert.AreEqual(expected, actual);
}
From 67ed222f45026dc3f2cf3d5be93a69df28ded947 Mon Sep 17 00:00:00 2001
From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com>
Date: Mon, 11 Sep 2023 12:02:16 -0500
Subject: [PATCH 022/293] Add conjugation
---
src/Mathematics.NET/Core/Complex.cs | 2 ++
src/Mathematics.NET/Core/IComplex.cs | 1 +
2 files changed, 3 insertions(+)
diff --git a/src/Mathematics.NET/Core/Complex.cs b/src/Mathematics.NET/Core/Complex.cs
index 8eea3147..354bc2cb 100644
--- a/src/Mathematics.NET/Core/Complex.cs
+++ b/src/Mathematics.NET/Core/Complex.cs
@@ -43,4 +43,6 @@ public Complex(T real, T imaginary)
public T Real => _real;
public T Imaginary => _imaginary;
+
+ public static Complex Conjugate(Complex z) => new(z._real, -z._imaginary);
}
diff --git a/src/Mathematics.NET/Core/IComplex.cs b/src/Mathematics.NET/Core/IComplex.cs
index 0797d998..d66a410f 100644
--- a/src/Mathematics.NET/Core/IComplex.cs
+++ b/src/Mathematics.NET/Core/IComplex.cs
@@ -39,4 +39,5 @@ public interface IComplex
{
public U Real { get; }
public virtual U Imaginary => U.Zero;
+ static abstract T Conjugate(T z);
}
From 3a958dc1d8e0d928074ae3dae92c15e3886d111d Mon Sep 17 00:00:00 2001
From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com>
Date: Mon, 11 Sep 2023 12:05:46 -0500
Subject: [PATCH 023/293] Update IComplex.cs
- Inherit basic arithmetical operations which have already been defined
---
src/Mathematics.NET/Core/IComplex.cs | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/src/Mathematics.NET/Core/IComplex.cs b/src/Mathematics.NET/Core/IComplex.cs
index d66a410f..17590f89 100644
--- a/src/Mathematics.NET/Core/IComplex.cs
+++ b/src/Mathematics.NET/Core/IComplex.cs
@@ -34,6 +34,10 @@ namespace Mathematics.NET.Core;
/// The type that implements the interface
/// A type that implements
public interface IComplex
+ : IAdditionOperation,
+ IDivisionOperation,
+ IMultiplicationOperation,
+ ISubtractionOperation
where T : IComplex
where U : INumber
{
From e9859c1513168166f9bf8628db5144ad9cc98b06 Mon Sep 17 00:00:00 2001
From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com>
Date: Mon, 11 Sep 2023 12:12:23 -0500
Subject: [PATCH 024/293] Update Complex.cs
- Implement addition, subtraction, and multiplication as required by interface. Division requires care and will be added later.
---
src/Mathematics.NET/Core/Complex.cs | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/src/Mathematics.NET/Core/Complex.cs b/src/Mathematics.NET/Core/Complex.cs
index 354bc2cb..af9d330a 100644
--- a/src/Mathematics.NET/Core/Complex.cs
+++ b/src/Mathematics.NET/Core/Complex.cs
@@ -44,5 +44,15 @@ public Complex(T real, T imaginary)
public T Real => _real;
public T Imaginary => _imaginary;
+ public static Complex operator +(Complex z, Complex w) => new(z._real + w._real, z._imaginary + w._imaginary);
+
+ public static Complex operator -(Complex z, Complex w) => new(z._real - w._real, z._imaginary - w._imaginary);
+
+ public static Complex operator *(Complex z, Complex w)
+ => new(z._real * w._real - z._imaginary * w._imaginary, z._real * w._imaginary + w._real * z._imaginary);
+
+ public static Complex operator /(Complex z, Complex w)
+ => throw new NotImplementedException();
+
public static Complex Conjugate(Complex z) => new(z._real, -z._imaginary);
}
From aaf6a481edc9d3e5d63d109b806a359ec03281b7 Mon Sep 17 00:00:00 2001
From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com>
Date: Mon, 11 Sep 2023 12:20:25 -0500
Subject: [PATCH 025/293] Add documentation comments
---
src/Mathematics.NET/Core/Complex.cs | 2 ++
1 file changed, 2 insertions(+)
diff --git a/src/Mathematics.NET/Core/Complex.cs b/src/Mathematics.NET/Core/Complex.cs
index af9d330a..a9adf67f 100644
--- a/src/Mathematics.NET/Core/Complex.cs
+++ b/src/Mathematics.NET/Core/Complex.cs
@@ -29,6 +29,8 @@
namespace Mathematics.NET.Core;
+/// Represents a complex number
+/// A type that implements
public readonly struct Complex : IComplex, T>
where T : INumber
{
From 55bde4497da06eb4fedcf79d6e0a1a463f6b01d1 Mon Sep 17 00:00:00 2001
From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com>
Date: Mon, 11 Sep 2023 12:20:34 -0500
Subject: [PATCH 026/293] Add documentation comments
---
src/Mathematics.NET/Core/IComplex.cs | 2 ++
1 file changed, 2 insertions(+)
diff --git a/src/Mathematics.NET/Core/IComplex.cs b/src/Mathematics.NET/Core/IComplex.cs
index 17590f89..f168d66c 100644
--- a/src/Mathematics.NET/Core/IComplex.cs
+++ b/src/Mathematics.NET/Core/IComplex.cs
@@ -41,7 +41,9 @@ public interface IComplex
where T : IComplex
where U : INumber
{
+ /// The real part of the complex number
public U Real { get; }
+ /// The imaginary part of the complex number
public virtual U Imaginary => U.Zero;
static abstract T Conjugate(T z);
}
From 571911fbc68d127e96b3ef3cadaab2b1f3cd782b Mon Sep 17 00:00:00 2001
From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com>
Date: Mon, 11 Sep 2023 16:22:27 -0500
Subject: [PATCH 027/293] Create INegationOperation.cs
- Add an interface that defines the negation operation
---
.../Core/Operations/INegationOperation.cs | 38 +++++++++++++++++++
1 file changed, 38 insertions(+)
create mode 100644 src/Mathematics.NET/Core/Operations/INegationOperation.cs
diff --git a/src/Mathematics.NET/Core/Operations/INegationOperation.cs b/src/Mathematics.NET/Core/Operations/INegationOperation.cs
new file mode 100644
index 00000000..7153054b
--- /dev/null
+++ b/src/Mathematics.NET/Core/Operations/INegationOperation.cs
@@ -0,0 +1,38 @@
+//
+// Mathematics.NET
+// https://github.com/HamletTanyavong/Mathematics.NET
+//
+// MIT License
+//
+// Copyright (c) 2023 Hamlet Tanyavong
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in all
+// copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+// SOFTWARE.
+//
+
+namespace Mathematics.NET.Core.Operations;
+
+/// Defines a mechanism for negating values
+/// The input type
+/// The output type
+public interface INegationOperation
+ where TInput : INegationOperation
+{
+ static abstract TResult operator -(TInput value);
+ static virtual TResult operator checked -(TInput value) => -value;
+}
From 2eb94982a7d3dddfd31cabf04b0a56b3f0bbd59e Mon Sep 17 00:00:00 2001
From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com>
Date: Mon, 11 Sep 2023 19:39:44 -0500
Subject: [PATCH 028/293] Use IFloatingPointIeee754 instead of INumber
- Remove test to reflect this change. Complex is no longer allowed.
---
src/Mathematics.NET/Core/Complex.cs | 4 ++--
src/Mathematics.NET/Core/IComplex.cs | 4 ++--
tests/Mathematics.NET.Tests/Core/ComplexTests.cs | 12 ------------
3 files changed, 4 insertions(+), 16 deletions(-)
diff --git a/src/Mathematics.NET/Core/Complex.cs b/src/Mathematics.NET/Core/Complex.cs
index a9adf67f..1c7720fc 100644
--- a/src/Mathematics.NET/Core/Complex.cs
+++ b/src/Mathematics.NET/Core/Complex.cs
@@ -30,9 +30,9 @@
namespace Mathematics.NET.Core;
/// Represents a complex number
-/// A type that implements
+/// A type that implements
public readonly struct Complex : IComplex, T>
- where T : INumber
+ where T : IFloatingPointIeee754
{
private readonly T _real;
private readonly T _imaginary;
diff --git a/src/Mathematics.NET/Core/IComplex.cs b/src/Mathematics.NET/Core/IComplex.cs
index f168d66c..b219914e 100644
--- a/src/Mathematics.NET/Core/IComplex.cs
+++ b/src/Mathematics.NET/Core/IComplex.cs
@@ -32,14 +32,14 @@ namespace Mathematics.NET.Core;
/// Defines support for complex numbers
/// The type that implements the interface
-/// A type that implements
+/// A type that implements
public interface IComplex
: IAdditionOperation,
IDivisionOperation,
IMultiplicationOperation,
ISubtractionOperation
where T : IComplex
- where U : INumber
+ where U : IFloatingPointIeee754
{
/// The real part of the complex number
public U Real { get; }
diff --git a/tests/Mathematics.NET.Tests/Core/ComplexTests.cs b/tests/Mathematics.NET.Tests/Core/ComplexTests.cs
index a78c592f..8a65c36e 100644
--- a/tests/Mathematics.NET.Tests/Core/ComplexTests.cs
+++ b/tests/Mathematics.NET.Tests/Core/ComplexTests.cs
@@ -31,18 +31,6 @@ namespace Mathematics.NET.Tests.Core;
[TestCategory("Core"), TestCategory("Complex Number")]
public sealed class ComplexTests
{
- [TestMethod]
- [DataRow(1, 2, 1, -2)]
- public void Conjugate_ComplexOfInt32_ReturnsConjugate(int inReal, int inImaginary, int outReal, int outImaginary)
- {
- Complex input = new(inReal, inImaginary);
- Complex expected = new(outReal, outImaginary);
-
- var actual = Complex.Conjugate(input);
-
- Assert.AreEqual(expected, actual);
- }
-
[TestMethod]
[DataRow(1.2, 2.3, 1.2, -2.3)]
public void Conjugate_ComplexOfDouble_ReturnsConjugate(double inReal, double inImaginary, double outReal, double outImaginary)
From 1a68b9388e7b7c20cfe58607831f04d2774f4c94 Mon Sep 17 00:00:00 2001
From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com>
Date: Mon, 11 Sep 2023 19:40:00 -0500
Subject: [PATCH 029/293] Update IComplex.cs
- Inherit negation operation
---
src/Mathematics.NET/Core/IComplex.cs | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/Mathematics.NET/Core/IComplex.cs b/src/Mathematics.NET/Core/IComplex.cs
index b219914e..2b372d9b 100644
--- a/src/Mathematics.NET/Core/IComplex.cs
+++ b/src/Mathematics.NET/Core/IComplex.cs
@@ -34,7 +34,8 @@ namespace Mathematics.NET.Core;
/// The type that implements the interface
/// A type that implements
public interface IComplex
- : IAdditionOperation,
+ : INegationOperation,
+ IAdditionOperation,
IDivisionOperation,
IMultiplicationOperation,
ISubtractionOperation
From 3b30259d5668236535bebc2593cd3221b762f71f Mon Sep 17 00:00:00 2001
From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com>
Date: Mon, 11 Sep 2023 19:45:58 -0500
Subject: [PATCH 030/293] Create IReal.cs
---
src/Mathematics.NET/Core/IReal.cs | 39 +++++++++++++++++++++++++++++++
1 file changed, 39 insertions(+)
create mode 100644 src/Mathematics.NET/Core/IReal.cs
diff --git a/src/Mathematics.NET/Core/IReal.cs b/src/Mathematics.NET/Core/IReal.cs
new file mode 100644
index 00000000..597af61b
--- /dev/null
+++ b/src/Mathematics.NET/Core/IReal.cs
@@ -0,0 +1,39 @@
+//
+// Mathematics.NET
+// https://github.com/HamletTanyavong/Mathematics.NET
+//
+// MIT License
+//
+// Copyright (c) 2023 Hamlet Tanyavong
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in all
+// copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+// SOFTWARE.
+//
+
+using System.Numerics;
+
+namespace Mathematics.NET.Core;
+
+/// Defines support for real numbers
+/// A type that implements the interface
+/// A type that implements
+public interface IReal : IComplex
+ where T : IReal
+ where U : IFloatingPointIeee754
+{
+}
From 2a327d335f93268655a0b8b7fb00a2a4f4557880 Mon Sep 17 00:00:00 2001
From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com>
Date: Mon, 11 Sep 2023 20:15:14 -0500
Subject: [PATCH 031/293] Implement negation operator
---
src/Mathematics.NET/Core/Complex.cs | 2 ++
1 file changed, 2 insertions(+)
diff --git a/src/Mathematics.NET/Core/Complex.cs b/src/Mathematics.NET/Core/Complex.cs
index 1c7720fc..6afa19a3 100644
--- a/src/Mathematics.NET/Core/Complex.cs
+++ b/src/Mathematics.NET/Core/Complex.cs
@@ -46,6 +46,8 @@ public Complex(T real, T imaginary)
public T Real => _real;
public T Imaginary => _imaginary;
+ public static Complex operator -(Complex z) => new(-z._real, -z._imaginary);
+
public static Complex operator +(Complex z, Complex w) => new(z._real + w._real, z._imaginary + w._imaginary);
public static Complex operator -(Complex z, Complex w) => new(z._real - w._real, z._imaginary - w._imaginary);
From 7119764485e39316d23c71dc16c04be50f6df732 Mon Sep 17 00:00:00 2001
From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com>
Date: Mon, 11 Sep 2023 20:33:46 -0500
Subject: [PATCH 032/293] Create Real number class and implement interface
---
src/Mathematics.NET/Core/Real.cs | 59 ++++++++++++++++++++++++++++++++
1 file changed, 59 insertions(+)
create mode 100644 src/Mathematics.NET/Core/Real.cs
diff --git a/src/Mathematics.NET/Core/Real.cs b/src/Mathematics.NET/Core/Real.cs
new file mode 100644
index 00000000..56cdbc7f
--- /dev/null
+++ b/src/Mathematics.NET/Core/Real.cs
@@ -0,0 +1,59 @@
+//
+// Mathematics.NET
+// https://github.com/HamletTanyavong/Mathematics.NET
+//
+// MIT License
+//
+// Copyright (c) 2023 Hamlet Tanyavong
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in all
+// copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+// SOFTWARE.
+//
+
+using System.Numerics;
+
+namespace Mathematics.NET.Core;
+
+/// Represents a real number
+/// A type that implements
+public readonly struct Real : IReal, T>
+ where T : IFloatingPointIeee754
+{
+ private readonly T _real;
+
+ public Real(T real)
+ {
+ _real = real;
+ }
+
+ // Real number properties
+
+ public Real Re => _real;
+
+ // Operators
+
+ public static Real operator -(Real value) => -value._real;
+ public static Real operator +(Real left, Real right) => left._real + right._real;
+ public static Real operator -(Real left, Real right) => left._real - right._real;
+ public static Real operator *(Real left, Real right) => left._real * right._real;
+ public static Real operator /(Real left, Real right) => left._real / right._real;
+
+ // Methods
+
+ public static Real Conjugate(Real z) => throw new NotImplementedException();
+}
From 4fce819ca091b1a3fe2d69f847776bd41237bf70 Mon Sep 17 00:00:00 2001
From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com>
Date: Mon, 11 Sep 2023 20:42:53 -0500
Subject: [PATCH 033/293] Use Real instead of T
- Update interface
- Add comments
---
src/Mathematics.NET/Core/Complex.cs | 14 ++++++++++----
src/Mathematics.NET/Core/IComplex.cs | 4 ++--
2 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/src/Mathematics.NET/Core/Complex.cs b/src/Mathematics.NET/Core/Complex.cs
index 6afa19a3..fbb362fa 100644
--- a/src/Mathematics.NET/Core/Complex.cs
+++ b/src/Mathematics.NET/Core/Complex.cs
@@ -34,8 +34,8 @@ namespace Mathematics.NET.Core;
public readonly struct Complex : IComplex, T>
where T : IFloatingPointIeee754
{
- private readonly T _real;
- private readonly T _imaginary;
+ private readonly Real _real;
+ private readonly Real _imaginary;
public Complex(T real, T imaginary)
{
@@ -43,8 +43,12 @@ public Complex(T real, T imaginary)
_imaginary = imaginary;
}
- public T Real => _real;
- public T Imaginary => _imaginary;
+ // Complex number properties
+
+ public Real Re => _real;
+ public Real Im => _imaginary;
+
+ // Operators
public static Complex operator -(Complex z) => new(-z._real, -z._imaginary);
@@ -58,5 +62,7 @@ public Complex(T real, T imaginary)
public static Complex operator /(Complex z, Complex w)
=> throw new NotImplementedException();
+ // Methods
+
public static Complex Conjugate(Complex z) => new(z._real, -z._imaginary);
}
diff --git a/src/Mathematics.NET/Core/IComplex.cs b/src/Mathematics.NET/Core/IComplex.cs
index 2b372d9b..441520f0 100644
--- a/src/Mathematics.NET/Core/IComplex.cs
+++ b/src/Mathematics.NET/Core/IComplex.cs
@@ -43,8 +43,8 @@ public interface IComplex
where U : IFloatingPointIeee754
{
/// The real part of the complex number
- public U Real { get; }
+ public Real Re { get; }
/// The imaginary part of the complex number
- public virtual U Imaginary => U.Zero;
+ public virtual Real Im => Real.Zero;
static abstract T Conjugate(T z);
}
From 73c7e64713a78aa370238b84da38c488e9d11df0 Mon Sep 17 00:00:00 2001
From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com>
Date: Mon, 11 Sep 2023 20:43:16 -0500
Subject: [PATCH 034/293] Add constructor
---
src/Mathematics.NET/Core/Complex.cs | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/src/Mathematics.NET/Core/Complex.cs b/src/Mathematics.NET/Core/Complex.cs
index fbb362fa..82f61bb1 100644
--- a/src/Mathematics.NET/Core/Complex.cs
+++ b/src/Mathematics.NET/Core/Complex.cs
@@ -37,7 +37,13 @@ namespace Mathematics.NET.Core;
private readonly Real _real;
private readonly Real _imaginary;
- public Complex(T real, T imaginary)
+ public Complex(Real real)
+ {
+ _real = real;
+ _imaginary = T.Zero;
+ }
+
+ public Complex(Real real, Real imaginary)
{
_real = real;
_imaginary = imaginary;
From 66ba75d89b815711cc1f2b6ec813f0b63fe13a40 Mon Sep 17 00:00:00 2001
From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com>
Date: Mon, 11 Sep 2023 20:44:23 -0500
Subject: [PATCH 035/293] Add constants Zero and One
---
src/Mathematics.NET/Core/Complex.cs | 5 +++++
src/Mathematics.NET/Core/IComplex.cs | 4 ++++
src/Mathematics.NET/Core/Real.cs | 5 +++++
3 files changed, 14 insertions(+)
diff --git a/src/Mathematics.NET/Core/Complex.cs b/src/Mathematics.NET/Core/Complex.cs
index 82f61bb1..0117faa3 100644
--- a/src/Mathematics.NET/Core/Complex.cs
+++ b/src/Mathematics.NET/Core/Complex.cs
@@ -54,6 +54,11 @@ public Complex(Real real, Real imaginary)
public Real Re => _real;
public Real Im => _imaginary;
+ // Constants
+
+ public static Complex Zero => new(Real.Zero, Real.Zero);
+ public static Complex One => new(Real.One, Real.Zero);
+
// Operators
public static Complex operator -(Complex z) => new(-z._real, -z._imaginary);
diff --git a/src/Mathematics.NET/Core/IComplex.cs b/src/Mathematics.NET/Core/IComplex.cs
index 441520f0..ef9e5a23 100644
--- a/src/Mathematics.NET/Core/IComplex.cs
+++ b/src/Mathematics.NET/Core/IComplex.cs
@@ -46,5 +46,9 @@ public interface IComplex
public Real Re { get; }
/// The imaginary part of the complex number
public virtual Real Im => Real.Zero;
+ /// Reprsents zero for the type
+ static abstract T Zero { get; }
+ /// Represents one for the type
+ static abstract T One { get; }
static abstract T Conjugate(T z);
}
diff --git a/src/Mathematics.NET/Core/Real.cs b/src/Mathematics.NET/Core/Real.cs
index 56cdbc7f..61541768 100644
--- a/src/Mathematics.NET/Core/Real.cs
+++ b/src/Mathematics.NET/Core/Real.cs
@@ -45,6 +45,11 @@ public Real(T real)
public Real Re => _real;
+ // Constants
+
+ public static Real Zero => T.Zero;
+ public static Real One => T.One;
+
// Operators
public static Real operator -(Real value) => -value._real;
From d329fc7db0c91dec136ab4f17ec25be7c8f3a6df Mon Sep 17 00:00:00 2001
From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com>
Date: Mon, 11 Sep 2023 20:45:11 -0500
Subject: [PATCH 036/293] Add and implement implicit operator
---
src/Mathematics.NET/Core/Complex.cs | 4 ++++
src/Mathematics.NET/Core/IComplex.cs | 1 +
src/Mathematics.NET/Core/Real.cs | 4 ++++
3 files changed, 9 insertions(+)
diff --git a/src/Mathematics.NET/Core/Complex.cs b/src/Mathematics.NET/Core/Complex.cs
index 0117faa3..b5f15844 100644
--- a/src/Mathematics.NET/Core/Complex.cs
+++ b/src/Mathematics.NET/Core/Complex.cs
@@ -76,4 +76,8 @@ public Complex(Real real, Real imaginary)
// Methods
public static Complex Conjugate(Complex z) => new(z._real, -z._imaginary);
+
+ // Implicit Operators
+
+ public static implicit operator Complex(T x) => new(x);
}
diff --git a/src/Mathematics.NET/Core/IComplex.cs b/src/Mathematics.NET/Core/IComplex.cs
index ef9e5a23..0b31b97f 100644
--- a/src/Mathematics.NET/Core/IComplex.cs
+++ b/src/Mathematics.NET/Core/IComplex.cs
@@ -51,4 +51,5 @@ public interface IComplex
/// Represents one for the type
static abstract T One { get; }
static abstract T Conjugate(T z);
+ static abstract implicit operator T(U x);
}
diff --git a/src/Mathematics.NET/Core/Real.cs b/src/Mathematics.NET/Core/Real.cs
index 61541768..f5460767 100644
--- a/src/Mathematics.NET/Core/Real.cs
+++ b/src/Mathematics.NET/Core/Real.cs
@@ -61,4 +61,8 @@ public Real(T real)
// Methods
public static Real Conjugate(Real z) => throw new NotImplementedException();
+
+ // Implicit operators
+
+ public static implicit operator Real(T x) => new(x);
}
From 3ec77c331c6ab250014e658efc18923897325cae Mon Sep 17 00:00:00 2001
From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com>
Date: Mon, 11 Sep 2023 20:48:08 -0500
Subject: [PATCH 037/293] Disable code style warning
---
src/Mathematics.NET/Core/Complex.cs | 2 ++
1 file changed, 2 insertions(+)
diff --git a/src/Mathematics.NET/Core/Complex.cs b/src/Mathematics.NET/Core/Complex.cs
index b5f15844..d5399e4a 100644
--- a/src/Mathematics.NET/Core/Complex.cs
+++ b/src/Mathematics.NET/Core/Complex.cs
@@ -25,6 +25,8 @@
// SOFTWARE.
//
+#pragma warning disable IDE0032
+
using System.Numerics;
namespace Mathematics.NET.Core;
From fb1a8cb727357412100e49af23e08df219d6d087 Mon Sep 17 00:00:00 2001
From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com>
Date: Mon, 11 Sep 2023 21:36:41 -0500
Subject: [PATCH 038/293] Disable code style warning
---
src/Mathematics.NET/Core/Real.cs | 2 ++
1 file changed, 2 insertions(+)
diff --git a/src/Mathematics.NET/Core/Real.cs b/src/Mathematics.NET/Core/Real.cs
index f5460767..76618f87 100644
--- a/src/Mathematics.NET/Core/Real.cs
+++ b/src/Mathematics.NET/Core/Real.cs
@@ -25,6 +25,8 @@
// SOFTWARE.
//
+#pragma warning disable IDE0032
+
using System.Numerics;
namespace Mathematics.NET.Core;
From f4f6ab42727fea38a7c49c615bad1b225243a889 Mon Sep 17 00:00:00 2001
From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com>
Date: Mon, 11 Sep 2023 22:05:37 -0500
Subject: [PATCH 039/293] Update IReal interface and implementation
- Define and implement way to get the backing value of a real number
---
src/Mathematics.NET/Core/IReal.cs | 2 ++
src/Mathematics.NET/Core/Real.cs | 1 +
2 files changed, 3 insertions(+)
diff --git a/src/Mathematics.NET/Core/IReal.cs b/src/Mathematics.NET/Core/IReal.cs
index 597af61b..a0ece939 100644
--- a/src/Mathematics.NET/Core/IReal.cs
+++ b/src/Mathematics.NET/Core/IReal.cs
@@ -36,4 +36,6 @@ public interface IReal : IComplex
where T : IReal
where U : IFloatingPointIeee754
{
+ /// The backing value of the type
+ U Value { get; }
}
diff --git a/src/Mathematics.NET/Core/Real.cs b/src/Mathematics.NET/Core/Real.cs
index 76618f87..8e76a273 100644
--- a/src/Mathematics.NET/Core/Real.cs
+++ b/src/Mathematics.NET/Core/Real.cs
@@ -46,6 +46,7 @@ public Real(T real)
// Real number properties
public Real Re => _real;
+ public T Value => _real;
// Constants
From 90355def069b4a81685b10b25fbe7e8f70e877f9 Mon Sep 17 00:00:00 2001
From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com>
Date: Mon, 11 Sep 2023 23:08:50 -0500
Subject: [PATCH 040/293] Update ComplexTests.cs
- Add test for verifying the phase of a complex number
---
tests/Mathematics.NET.Tests/Core/ComplexTests.cs | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/tests/Mathematics.NET.Tests/Core/ComplexTests.cs b/tests/Mathematics.NET.Tests/Core/ComplexTests.cs
index 8a65c36e..664bb4ab 100644
--- a/tests/Mathematics.NET.Tests/Core/ComplexTests.cs
+++ b/tests/Mathematics.NET.Tests/Core/ComplexTests.cs
@@ -42,4 +42,18 @@ public void Conjugate_ComplexOfDouble_ReturnsConjugate(double inReal, double inI
Assert.AreEqual(expected, actual);
}
+
+ [TestMethod]
+ [DataRow(1, 1, 0, Math.PI / 2)]
+ [DataRow(1, -1, -Math.PI / 2, 0)]
+ [DataRow(-1, 1, Math.PI / 2, Math.PI)]
+ [DataRow(-1, -1, -Math.PI, -Math.PI / 2)]
+ public void Phase_ComplexOfDouble_ReturnsAngleInCorrectQuadrant(double inReal, double inImaginary, double min, double max)
+ {
+ Complex z = new(inReal, inImaginary);
+
+ var actual = z.Phase.Value;
+
+ Assert.IsTrue(min <= actual && actual <= max);
+ }
}
From fe1cc305a01d1f9cb6734027d913369c4b0a794b Mon Sep 17 00:00:00 2001
From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com>
Date: Tue, 12 Sep 2023 00:01:22 -0500
Subject: [PATCH 041/293] Add Magnitude and Phase properties
---
src/Mathematics.NET/Core/Complex.cs | 2 ++
src/Mathematics.NET/Core/IComplex.cs | 4 ++++
2 files changed, 6 insertions(+)
diff --git a/src/Mathematics.NET/Core/Complex.cs b/src/Mathematics.NET/Core/Complex.cs
index d5399e4a..698a9606 100644
--- a/src/Mathematics.NET/Core/Complex.cs
+++ b/src/Mathematics.NET/Core/Complex.cs
@@ -55,6 +55,8 @@ public Complex(Real real, Real imaginary)
public Real Re => _real;
public Real Im => _imaginary;
+ public Real Magnitude => T.Hypot(_real.Value, _imaginary.Value);
+ public Real Phase => T.Atan2(_imaginary.Value, _real.Value);
// Constants
diff --git a/src/Mathematics.NET/Core/IComplex.cs b/src/Mathematics.NET/Core/IComplex.cs
index 0b31b97f..9e119419 100644
--- a/src/Mathematics.NET/Core/IComplex.cs
+++ b/src/Mathematics.NET/Core/IComplex.cs
@@ -46,6 +46,10 @@ public interface IComplex
public Real Re { get; }
/// The imaginary part of the complex number
public virtual Real Im => Real.Zero;
+ /// The magnitude of the complex number in polar coordinates
+ public virtual Real Magnitude => U.Hypot(Re.Value, Im.Value);
+ /// The phase of the complex number in polar coordinates
+ public virtual Real Phase => U.Atan2(Im.Value, Re.Value);
/// Reprsents zero for the type
static abstract T Zero { get; }
/// Represents one for the type
From 015ed698826c138f2cb8501bc337e7cf0465d62a Mon Sep 17 00:00:00 2001
From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com>
Date: Tue, 12 Sep 2023 00:37:48 -0500
Subject: [PATCH 042/293] Add constants as fields
- Add ImUnit to represent the imaginary unit
---
src/Mathematics.NET/Core/Complex.cs | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/src/Mathematics.NET/Core/Complex.cs b/src/Mathematics.NET/Core/Complex.cs
index 698a9606..05fcbdbb 100644
--- a/src/Mathematics.NET/Core/Complex.cs
+++ b/src/Mathematics.NET/Core/Complex.cs
@@ -36,6 +36,10 @@ namespace Mathematics.NET.Core;
public readonly struct Complex : IComplex, T>
where T : IFloatingPointIeee754
{
+ public static readonly Complex Zero = new(Real.Zero, Real.Zero);
+ public static readonly Complex One = new(Real.One, Real.Zero);
+ public static readonly Complex ImUnit = new(Real.Zero, Real.One);
+
private readonly Real _real;
private readonly Real _imaginary;
@@ -60,8 +64,8 @@ public Complex(Real real, Real imaginary)
// Constants
- public static Complex Zero => new(Real.Zero, Real.Zero);
- public static Complex One => new(Real.One, Real.Zero);
+ static Complex IComplex, T>.Zero => Zero;
+ static Complex IComplex, T>.One => One;
// Operators
From f1e444536057dcf5fac799f133f17c60e3975fd2 Mon Sep 17 00:00:00 2001
From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com>
Date: Tue, 12 Sep 2023 09:00:19 -0500
Subject: [PATCH 043/293] Add constants as fields
---
src/Mathematics.NET/Core/Real.cs | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/src/Mathematics.NET/Core/Real.cs b/src/Mathematics.NET/Core/Real.cs
index 8e76a273..c44070fc 100644
--- a/src/Mathematics.NET/Core/Real.cs
+++ b/src/Mathematics.NET/Core/Real.cs
@@ -36,6 +36,9 @@ namespace Mathematics.NET.Core;
public readonly struct Real : IReal, T>
where T : IFloatingPointIeee754
{
+ public static readonly Real Zero = T.Zero;
+ public static readonly Real One = T.One;
+
private readonly T _real;
public Real(T real)
@@ -50,8 +53,8 @@ public Real(T real)
// Constants
- public static Real Zero => T.Zero;
- public static Real One => T.One;
+ static Real IComplex, T>.Zero => Zero;
+ static Real IComplex, T>.One => One;
// Operators
From aa06f12241e6bc2ad28af9ae5151761897c02c34 Mon Sep 17 00:00:00 2001
From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com>
Date: Tue, 12 Sep 2023 09:01:00 -0500
Subject: [PATCH 044/293] Add NaN for complex and real numbers
---
src/Mathematics.NET/Core/Complex.cs | 2 ++
src/Mathematics.NET/Core/IComplex.cs | 1 +
src/Mathematics.NET/Core/Real.cs | 2 ++
3 files changed, 5 insertions(+)
diff --git a/src/Mathematics.NET/Core/Complex.cs b/src/Mathematics.NET/Core/Complex.cs
index 05fcbdbb..0c51f121 100644
--- a/src/Mathematics.NET/Core/Complex.cs
+++ b/src/Mathematics.NET/Core/Complex.cs
@@ -39,6 +39,7 @@ namespace Mathematics.NET.Core;
public static readonly Complex Zero = new(Real.Zero, Real.Zero);
public static readonly Complex One = new(Real.One, Real.Zero);
public static readonly Complex ImUnit = new(Real.Zero, Real.One);
+ public static readonly Complex NaN = new(Real.NaN, Real.NaN);
private readonly Real _real;
private readonly Real _imaginary;
@@ -66,6 +67,7 @@ public Complex(Real real, Real imaginary)
static Complex IComplex, T>.Zero => Zero;
static Complex IComplex, T>.One => One;
+ static Complex IComplex, T>.NaN => NaN;
// Operators
diff --git a/src/Mathematics.NET/Core/IComplex.cs b/src/Mathematics.NET/Core/IComplex.cs
index 9e119419..528e5611 100644
--- a/src/Mathematics.NET/Core/IComplex.cs
+++ b/src/Mathematics.NET/Core/IComplex.cs
@@ -54,6 +54,7 @@ public interface IComplex
static abstract T Zero { get; }
/// Represents one for the type
static abstract T One { get; }
+ static abstract T NaN { get; }
static abstract T Conjugate(T z);
static abstract implicit operator T(U x);
}
diff --git a/src/Mathematics.NET/Core/Real.cs b/src/Mathematics.NET/Core/Real.cs
index c44070fc..5be625dc 100644
--- a/src/Mathematics.NET/Core/Real.cs
+++ b/src/Mathematics.NET/Core/Real.cs
@@ -38,6 +38,7 @@ namespace Mathematics.NET.Core;
{
public static readonly Real Zero = T.Zero;
public static readonly Real One = T.One;
+ public static readonly Real NaN = T.NaN;
private readonly T _real;
@@ -55,6 +56,7 @@ public Real(T real)
static Real IComplex, T>.Zero => Zero;
static Real IComplex, T>.One => One;
+ static Real IComplex, T>.NaN => NaN;
// Operators
From e60c2e771b28b6cded7b90755fac8e1ac380ce94 Mon Sep 17 00:00:00 2001
From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com>
Date: Tue, 12 Sep 2023 09:32:47 -0500
Subject: [PATCH 045/293] Rename parameters for clarity
---
tests/Mathematics.NET.Tests/Core/ComplexTests.cs | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tests/Mathematics.NET.Tests/Core/ComplexTests.cs b/tests/Mathematics.NET.Tests/Core/ComplexTests.cs
index 664bb4ab..4d7e6eef 100644
--- a/tests/Mathematics.NET.Tests/Core/ComplexTests.cs
+++ b/tests/Mathematics.NET.Tests/Core/ComplexTests.cs
@@ -48,12 +48,12 @@ public void Conjugate_ComplexOfDouble_ReturnsConjugate(double inReal, double inI
[DataRow(1, -1, -Math.PI / 2, 0)]
[DataRow(-1, 1, Math.PI / 2, Math.PI)]
[DataRow(-1, -1, -Math.PI, -Math.PI / 2)]
- public void Phase_ComplexOfDouble_ReturnsAngleInCorrectQuadrant(double inReal, double inImaginary, double min, double max)
+ public void Phase_ComplexOfDouble_ReturnsAngleInCorrectQuadrant(double inReal, double inImaginary, double expectedMin, double expectedMax)
{
Complex z = new(inReal, inImaginary);
var actual = z.Phase.Value;
- Assert.IsTrue(min <= actual && actual <= max);
+ Assert.IsTrue(expectedMin <= actual && actual <= expectedMax);
}
}
From fc154e97735e147e01a4336e37456636ae109c5c Mon Sep 17 00:00:00 2001
From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com>
Date: Tue, 12 Sep 2023 10:03:42 -0500
Subject: [PATCH 046/293] Rename field
---
src/Mathematics.NET/Core/Complex.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/Mathematics.NET/Core/Complex.cs b/src/Mathematics.NET/Core/Complex.cs
index 0c51f121..e8d61efe 100644
--- a/src/Mathematics.NET/Core/Complex.cs
+++ b/src/Mathematics.NET/Core/Complex.cs
@@ -38,7 +38,7 @@ namespace Mathematics.NET.Core;
{
public static readonly Complex Zero = new(Real.Zero, Real.Zero);
public static readonly Complex One = new(Real.One, Real.Zero);
- public static readonly Complex ImUnit = new(Real.Zero, Real.One);
+ public static readonly Complex ImaginaryUnit = new(Real.Zero, Real.One);
public static readonly Complex NaN = new(Real.NaN, Real.NaN);
private readonly Real _real;
From 83306dacda7c0f5652b1d72a78bb43017493be4d Mon Sep 17 00:00:00 2001
From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com>
Date: Tue, 12 Sep 2023 10:11:41 -0500
Subject: [PATCH 047/293] Rename field
---
src/Mathematics.NET/Core/Real.cs | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/src/Mathematics.NET/Core/Real.cs b/src/Mathematics.NET/Core/Real.cs
index 5be625dc..608d5fa6 100644
--- a/src/Mathematics.NET/Core/Real.cs
+++ b/src/Mathematics.NET/Core/Real.cs
@@ -40,17 +40,17 @@ namespace Mathematics.NET.Core;
public static readonly Real One = T.One;
public static readonly Real NaN = T.NaN;
- private readonly T _real;
+ private readonly T _value;
public Real(T real)
{
- _real = real;
+ _value = real;
}
// Real number properties
- public Real Re => _real;
- public T Value => _real;
+ public Real Re => _value;
+ public T Value => _value;
// Constants
@@ -60,11 +60,11 @@ public Real(T real)
// Operators
- public static Real operator -(Real value) => -value._real;
- public static Real operator +(Real left, Real right) => left._real + right._real;
- public static Real operator -(Real left, Real right) => left._real - right._real;
- public static Real operator *(Real left, Real right) => left._real * right._real;
- public static Real operator /(Real left, Real right) => left._real / right._real;
+ public static Real operator -(Real value) => -value._value;
+ public static Real operator +(Real left, Real right) => left._value + right._value;
+ public static Real operator -(Real left, Real right) => left._value - right._value;
+ public static Real operator *(Real left, Real right) => left._value * right._value;
+ public static Real operator /(Real left, Real right) => left._value / right._value;
// Methods
From f7a6e68d49b01bc80ee743c4ba60e0657376b961 Mon Sep 17 00:00:00 2001
From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com>
Date: Tue, 12 Sep 2023 10:30:37 -0500
Subject: [PATCH 048/293] Add documentation comment
---
src/Mathematics.NET/Core/IComplex.cs | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/Mathematics.NET/Core/IComplex.cs b/src/Mathematics.NET/Core/IComplex.cs
index 528e5611..a15fff27 100644
--- a/src/Mathematics.NET/Core/IComplex.cs
+++ b/src/Mathematics.NET/Core/IComplex.cs
@@ -54,6 +54,7 @@ public interface IComplex
static abstract T Zero { get; }
/// Represents one for the type
static abstract T One { get; }
+ /// Represents NaN for the type
static abstract T NaN { get; }
static abstract T Conjugate(T z);
static abstract implicit operator T(U x);
From 232eb41a08d3402a58a95e971798c5cb051244e4 Mon Sep 17 00:00:00 2001
From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com>
Date: Tue, 12 Sep 2023 10:35:23 -0500
Subject: [PATCH 049/293] Update ComplexTests.cs
- Add test for verifying the magnitude of a complex number
---
tests/Mathematics.NET.Tests/Core/ComplexTests.cs | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/tests/Mathematics.NET.Tests/Core/ComplexTests.cs b/tests/Mathematics.NET.Tests/Core/ComplexTests.cs
index 4d7e6eef..61973068 100644
--- a/tests/Mathematics.NET.Tests/Core/ComplexTests.cs
+++ b/tests/Mathematics.NET.Tests/Core/ComplexTests.cs
@@ -43,6 +43,17 @@ public void Conjugate_ComplexOfDouble_ReturnsConjugate(double inReal, double inI
Assert.AreEqual(expected, actual);
}
+ [TestMethod]
+ [DataRow(3, 4, 5)]
+ public void Magnitude_ComplexOfDouble_ReturnsMagnitude(double inReal, double inImaginary, double expected)
+ {
+ Complex z = new(inReal, inImaginary);
+
+ var actual = z.Magnitude.Value;
+
+ Assert.AreEqual(expected, actual);
+ }
+
[TestMethod]
[DataRow(1, 1, 0, Math.PI / 2)]
[DataRow(1, -1, -Math.PI / 2, 0)]
From 23740dc5919ae3d164ea0dcf221bdee9a2dd7d7a Mon Sep 17 00:00:00 2001
From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com>
Date: Tue, 12 Sep 2023 10:51:20 -0500
Subject: [PATCH 050/293] Add positive and negative infinities
---
src/Mathematics.NET/Core/IReal.cs | 4 ++++
src/Mathematics.NET/Core/Real.cs | 4 ++++
2 files changed, 8 insertions(+)
diff --git a/src/Mathematics.NET/Core/IReal.cs b/src/Mathematics.NET/Core/IReal.cs
index a0ece939..8e737647 100644
--- a/src/Mathematics.NET/Core/IReal.cs
+++ b/src/Mathematics.NET/Core/IReal.cs
@@ -38,4 +38,8 @@ public interface IReal : IComplex
{
/// The backing value of the type
U Value { get; }
+ /// Represents negative infinty for the type
+ static abstract T NegativeInfinity { get; }
+ /// Represents positive infinity for the type
+ static abstract T PositiveInfinity { get; }
}
diff --git a/src/Mathematics.NET/Core/Real.cs b/src/Mathematics.NET/Core/Real.cs
index 608d5fa6..89540255 100644
--- a/src/Mathematics.NET/Core/Real.cs
+++ b/src/Mathematics.NET/Core/Real.cs
@@ -39,6 +39,8 @@ namespace Mathematics.NET.Core;
public static readonly Real Zero = T.Zero;
public static readonly Real One = T.One;
public static readonly Real NaN = T.NaN;
+ public static readonly Real NegativeInfinity = T.NegativeInfinity;
+ public static readonly Real PositiveInfinity = T.PositiveInfinity;
private readonly T _value;
@@ -57,6 +59,8 @@ public Real(T real)
static Real IComplex, T>.Zero => Zero;
static Real IComplex, T>.One => One;
static Real IComplex, T>.NaN => NaN;
+ static Real IReal, T>.NegativeInfinity => NegativeInfinity;
+ static Real IReal, T>.PositiveInfinity => PositiveInfinity;
// Operators
From 8a8f382ee25d1c76a1e14061b7069affd10361b2 Mon Sep 17 00:00:00 2001
From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com>
Date: Tue, 12 Sep 2023 11:13:37 -0500
Subject: [PATCH 051/293] Implement conjugate
---
src/Mathematics.NET/Core/Real.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/Mathematics.NET/Core/Real.cs b/src/Mathematics.NET/Core/Real.cs
index 89540255..68a76726 100644
--- a/src/Mathematics.NET/Core/Real.cs
+++ b/src/Mathematics.NET/Core/Real.cs
@@ -72,7 +72,7 @@ public Real(T real)
// Methods
- public static Real Conjugate(Real z) => throw new NotImplementedException();
+ public static Real Conjugate(Real x) => x;
// Implicit operators
From ec1fdfef171f27f1a9051cba0fce3b44cf2e5871 Mon Sep 17 00:00:00 2001
From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com>
Date: Tue, 12 Sep 2023 12:17:20 -0500
Subject: [PATCH 052/293] Update ComplexTests.cs
- Add test for verifying the TryFormat method
---
tests/Mathematics.NET.Tests/Core/ComplexTests.cs | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/tests/Mathematics.NET.Tests/Core/ComplexTests.cs b/tests/Mathematics.NET.Tests/Core/ComplexTests.cs
index 61973068..6ca910d6 100644
--- a/tests/Mathematics.NET.Tests/Core/ComplexTests.cs
+++ b/tests/Mathematics.NET.Tests/Core/ComplexTests.cs
@@ -67,4 +67,19 @@ public void Phase_ComplexOfDouble_ReturnsAngleInCorrectQuadrant(double inReal, d
Assert.IsTrue(expectedMin <= actual && actual <= expectedMax);
}
+
+ [TestMethod]
+ [DataRow(1.2, 2.3, 10, null, "(1.2, 2.3)")]
+ [DataRow(1.23, 3.4567, 14, "ALL", "(1.23, 3.4567)")]
+ [DataRow(4.537, 2.3, 5, "RE", "4.537")]
+ [DataRow(1.2, 7, 1, "IM", "7")]
+ public void TryFormat_ComplexOfDouble_ReturnsSpanOfCharacters(double inReal, double inImaginary, int length, string? format, string expected)
+ {
+ Complex z = new(inReal, inImaginary);
+
+ Span actual = new char[length];
+ _ = z.TryFormat(actual, out int _, format, null);
+
+ CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray());
+ }
}
From 0d633fcd5f51bc9fc73245756ab8d820c982cdf2 Mon Sep 17 00:00:00 2001
From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com>
Date: Tue, 12 Sep 2023 12:26:07 -0500
Subject: [PATCH 053/293] Use ISpanFormattable
- Implement TryFormat in real and complex number classes
---
src/Mathematics.NET/Core/Complex.cs | 60 ++++++++++++++++++++++++++++
src/Mathematics.NET/Core/IComplex.cs | 3 +-
src/Mathematics.NET/Core/Real.cs | 7 ++++
3 files changed, 69 insertions(+), 1 deletion(-)
diff --git a/src/Mathematics.NET/Core/Complex.cs b/src/Mathematics.NET/Core/Complex.cs
index e8d61efe..5ff8f14c 100644
--- a/src/Mathematics.NET/Core/Complex.cs
+++ b/src/Mathematics.NET/Core/Complex.cs
@@ -27,6 +27,7 @@
#pragma warning disable IDE0032
+using System.Globalization;
using System.Numerics;
namespace Mathematics.NET.Core;
@@ -87,6 +88,65 @@ public Complex(Real real, Real imaginary)
public static Complex Conjugate(Complex z) => new(z._real, -z._imaginary);
+ // Formatting
+
+ public string ToString(string? format, IFormatProvider? formatProvider) => throw new NotImplementedException();
+
+ public bool TryFormat(Span destination, out int charsWritten, ReadOnlySpan format, IFormatProvider? provider)
+ {
+ format = format.IsEmpty ? "ALL" : format.ToString().ToUpperInvariant();
+ provider ??= NumberFormatInfo.InvariantInfo;
+
+ if (format is "ALL")
+ {
+ // There are a minimum of 6 characters for "(0, 0)".
+ int charsCurrentlyWritten = 0;
+ if (destination.Length < 6)
+ {
+ charsWritten = charsCurrentlyWritten;
+ return false;
+ }
+
+ destination[charsCurrentlyWritten++] = '(';
+
+ bool tryFormatSucceeded = _real.TryFormat(destination[charsCurrentlyWritten..], out int tryFormatCharsWritten, null, provider);
+ if (!tryFormatSucceeded)
+ {
+ charsWritten = charsCurrentlyWritten;
+ return false;
+ }
+ charsCurrentlyWritten += tryFormatCharsWritten;
+
+ destination[charsCurrentlyWritten++] = ',';
+ destination[charsCurrentlyWritten++] = ' ';
+
+ tryFormatSucceeded = _imaginary.TryFormat(destination[charsCurrentlyWritten..], out tryFormatCharsWritten, null, provider);
+ if (!tryFormatSucceeded)
+ {
+ charsWritten = charsCurrentlyWritten;
+ return false;
+ }
+ charsCurrentlyWritten += tryFormatCharsWritten;
+
+ destination[charsCurrentlyWritten++] = ')';
+
+ charsWritten = charsCurrentlyWritten;
+ return true;
+ }
+ else if (format is "RE")
+ {
+ return _real.TryFormat(destination, out charsWritten, null, provider);
+ }
+ else if (format is "IM")
+ {
+ return _imaginary.TryFormat(destination, out charsWritten, null, provider);
+ }
+ else
+ {
+ throw new FormatException($"The \"{format}\" format is not supported.");
+ }
+ }
+
// Implicit Operators
public static implicit operator Complex(T x) => new(x);
diff --git a/src/Mathematics.NET/Core/IComplex.cs b/src/Mathematics.NET/Core/IComplex.cs
index a15fff27..9ce46fcd 100644
--- a/src/Mathematics.NET/Core/IComplex.cs
+++ b/src/Mathematics.NET/Core/IComplex.cs
@@ -38,7 +38,8 @@ public interface IComplex
IAdditionOperation,
IDivisionOperation,
IMultiplicationOperation,
- ISubtractionOperation
+ ISubtractionOperation,
+ ISpanFormattable
where T : IComplex
where U : IFloatingPointIeee754
{
diff --git a/src/Mathematics.NET/Core/Real.cs b/src/Mathematics.NET/Core/Real.cs
index 68a76726..40ae03e4 100644
--- a/src/Mathematics.NET/Core/Real.cs
+++ b/src/Mathematics.NET/Core/Real.cs
@@ -74,6 +74,13 @@ public Real(T real)
public static Real Conjugate(Real x) => x;
+ // Formatting
+
+ public string ToString(string? format, IFormatProvider? formatProvider) => throw new NotImplementedException();
+
+ public bool TryFormat(Span destination, out int charsWritten, ReadOnlySpan format, IFormatProvider? provider)
+ => _value.TryFormat(destination, out charsWritten, null, provider);
+
// Implicit operators
public static implicit operator Real(T x) => new(x);
From cdae1f5e347cd4f6891705b3cb21091c5998857d Mon Sep 17 00:00:00 2001
From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com>
Date: Tue, 12 Sep 2023 12:52:46 -0500
Subject: [PATCH 054/293] Implement ToString
---
src/Mathematics.NET/Core/Complex.cs | 25 ++++++++++++++++++++++++-
src/Mathematics.NET/Core/Real.cs | 4 +++-
2 files changed, 27 insertions(+), 2 deletions(-)
diff --git a/src/Mathematics.NET/Core/Complex.cs b/src/Mathematics.NET/Core/Complex.cs
index 5ff8f14c..3d4ab8ce 100644
--- a/src/Mathematics.NET/Core/Complex.cs
+++ b/src/Mathematics.NET/Core/Complex.cs
@@ -90,7 +90,30 @@ public Complex(Real real, Real imaginary)
// Formatting
- public string ToString(string? format, IFormatProvider? formatProvider) => throw new NotImplementedException();
+ public override string ToString() => ToString(null, null);
+
+ public string ToString(string? format, IFormatProvider? formatProvider)
+ {
+ format = string.IsNullOrEmpty(format) ? "ALL" : format.ToUpperInvariant();
+ formatProvider ??= NumberFormatInfo.InvariantInfo;
+
+ if (format is "ALL")
+ {
+ return string.Format(formatProvider, "({0}, {1})", _real, _imaginary);
+ }
+ else if (format is "RE")
+ {
+ return string.Format(formatProvider, "{0}", _real);
+ }
+ else if (format is "IM")
+ {
+ return string.Format(formatProvider, "{0}", _imaginary);
+ }
+ else
+ {
+ throw new FormatException($"The \"{format}\" format is not supported.");
+ }
+ }
public bool TryFormat(Span destination, out int charsWritten, ReadOnlySpan format, IFormatProvider? provider)
{
diff --git a/src/Mathematics.NET/Core/Real.cs b/src/Mathematics.NET/Core/Real.cs
index 40ae03e4..140d9374 100644
--- a/src/Mathematics.NET/Core/Real.cs
+++ b/src/Mathematics.NET/Core/Real.cs
@@ -76,7 +76,9 @@ public Real(T real)
// Formatting
- public string ToString(string? format, IFormatProvider? formatProvider) => throw new NotImplementedException();
+ public override string ToString() => ToString(null, null);
+
+ public string ToString(string? format, IFormatProvider? formatProvider) => string.Format(formatProvider, "{0}", _value);
public bool TryFormat(Span destination, out int charsWritten, ReadOnlySpan format, IFormatProvider? provider)
=> _value.TryFormat(destination, out charsWritten, null, provider);
From 1b7ce4f8d0038e1b151b62e73da5b67b1313584d Mon Sep 17 00:00:00 2001
From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com>
Date: Tue, 12 Sep 2023 12:59:30 -0500
Subject: [PATCH 055/293] Update ComplexTests.cs
- Add test for ToString method
---
tests/Mathematics.NET.Tests/Core/ComplexTests.cs | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/tests/Mathematics.NET.Tests/Core/ComplexTests.cs b/tests/Mathematics.NET.Tests/Core/ComplexTests.cs
index 6ca910d6..da30b833 100644
--- a/tests/Mathematics.NET.Tests/Core/ComplexTests.cs
+++ b/tests/Mathematics.NET.Tests/Core/ComplexTests.cs
@@ -68,6 +68,20 @@ public void Phase_ComplexOfDouble_ReturnsAngleInCorrectQuadrant(double inReal, d
Assert.IsTrue(expectedMin <= actual && actual <= expectedMax);
}
+ [TestMethod]
+ [DataRow(1.23, 4.567, null, "(1.23, 4.567)")]
+ [DataRow(24.56, 9.23, "ALL", "(24.56, 9.23)")]
+ [DataRow(62.151, 27, "RE", "62.151")]
+ [DataRow(7.345, 124.841, "IM", "124.841")]
+ public void ToString_ComplexOfDouble_ReturnsString(double inReal, double inImaginary, string? format, string expected)
+ {
+ Complex z = new(inReal, inImaginary);
+
+ var actual = z.ToString(format, null);
+
+ Assert.AreEqual(expected, actual);
+ }
+
[TestMethod]
[DataRow(1.2, 2.3, 10, null, "(1.2, 2.3)")]
[DataRow(1.23, 3.4567, 14, "ALL", "(1.23, 3.4567)")]
From 51f1511ce162d79f982806e76dc7d69f51352faa Mon Sep 17 00:00:00 2001
From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com>
Date: Tue, 12 Sep 2023 17:39:27 -0500
Subject: [PATCH 056/293] Update Complex.cs
- Fix error that occurs when destination span is too short
---
src/Mathematics.NET/Core/Complex.cs | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)
diff --git a/src/Mathematics.NET/Core/Complex.cs b/src/Mathematics.NET/Core/Complex.cs
index 3d4ab8ce..4038cc91 100644
--- a/src/Mathematics.NET/Core/Complex.cs
+++ b/src/Mathematics.NET/Core/Complex.cs
@@ -133,23 +133,33 @@ public bool TryFormat(Span destination, out int charsWritten, ReadOnlySpan
destination[charsCurrentlyWritten++] = '(';
bool tryFormatSucceeded = _real.TryFormat(destination[charsCurrentlyWritten..], out int tryFormatCharsWritten, null, provider);
- if (!tryFormatSucceeded)
+ charsCurrentlyWritten += tryFormatCharsWritten;
+ if (!tryFormatSucceeded || destination.Length < charsCurrentlyWritten + 1)
{
charsWritten = charsCurrentlyWritten;
return false;
}
- charsCurrentlyWritten += tryFormatCharsWritten;
destination[charsCurrentlyWritten++] = ',';
+ if (destination.Length < charsCurrentlyWritten + 1)
+ {
+ charsWritten = charsCurrentlyWritten;
+ return false;
+ }
destination[charsCurrentlyWritten++] = ' ';
+ if (destination.Length < charsCurrentlyWritten + 1)
+ {
+ charsWritten = charsCurrentlyWritten;
+ return false;
+ }
tryFormatSucceeded = _imaginary.TryFormat(destination[charsCurrentlyWritten..], out tryFormatCharsWritten, null, provider);
- if (!tryFormatSucceeded)
+ charsCurrentlyWritten += tryFormatCharsWritten;
+ if (!tryFormatSucceeded || destination.Length < charsCurrentlyWritten + 1)
{
charsWritten = charsCurrentlyWritten;
return false;
}
- charsCurrentlyWritten += tryFormatCharsWritten;
destination[charsCurrentlyWritten++] = ')';
From e9b86f38d46cdb2298683fc012c2e8f7ffe33fd2 Mon Sep 17 00:00:00 2001
From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com>
Date: Tue, 12 Sep 2023 17:51:29 -0500
Subject: [PATCH 057/293] Update ComplexTests.cs
- Add a test to check if TryFormat gives the correct amount of characters written even if it returns false
---
.../Core/ComplexTests.cs | 22 +++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/tests/Mathematics.NET.Tests/Core/ComplexTests.cs b/tests/Mathematics.NET.Tests/Core/ComplexTests.cs
index da30b833..f3bf35c4 100644
--- a/tests/Mathematics.NET.Tests/Core/ComplexTests.cs
+++ b/tests/Mathematics.NET.Tests/Core/ComplexTests.cs
@@ -82,6 +82,28 @@ public void ToString_ComplexOfDouble_ReturnsString(double inReal, double inImagi
Assert.AreEqual(expected, actual);
}
+ [TestMethod]
+ [DataRow(0, 0, 6, 6)]
+ [DataRow(1.23, 45.678, 14, 14)]
+ [DataRow(1.23, 45.678, 13, 13)]
+ [DataRow(1.23, 45.678, 9, 7)]
+ [DataRow(1.23, 45.678, 6, 6)]
+ [DataRow(1.23, 45.678, 1, 0)]
+ [DataRow(0, 1.2345, 6, 4)]
+ [DataRow(1.2345, 0, 6, 1)]
+ [DataRow(1.2345, 0, 6, 1)]
+ [DataRow(1.2345, 0, 7, 7)]
+ [DataRow(1.2345, 0, 8, 8)]
+ public void TryFormat_ComplexOfDoubleWithShortDestinationSpan_ReturnsCorrectNumberOfCharsWritten(double inReal, double inImaginary, int length, int expected)
+ {
+ Complex z = new(inReal, inImaginary);
+
+ Span span = new char[length];
+ _ = z.TryFormat(span, out int actual, null, null);
+
+ Assert.AreEqual(expected, actual);
+ }
+
[TestMethod]
[DataRow(1.2, 2.3, 10, null, "(1.2, 2.3)")]
[DataRow(1.23, 3.4567, 14, "ALL", "(1.23, 3.4567)")]
From bd6c0206a7efdbbaa6de520cc07e3e1939e94528 Mon Sep 17 00:00:00 2001
From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com>
Date: Tue, 12 Sep 2023 17:51:39 -0500
Subject: [PATCH 058/293] Update ComplexTests.cs
- Add tests to verify that TryFormat returns the correct Boolean
---
.../Core/ComplexTests.cs | 26 +++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/tests/Mathematics.NET.Tests/Core/ComplexTests.cs b/tests/Mathematics.NET.Tests/Core/ComplexTests.cs
index f3bf35c4..2a75ad91 100644
--- a/tests/Mathematics.NET.Tests/Core/ComplexTests.cs
+++ b/tests/Mathematics.NET.Tests/Core/ComplexTests.cs
@@ -82,6 +82,32 @@ public void ToString_ComplexOfDouble_ReturnsString(double inReal, double inImagi
Assert.AreEqual(expected, actual);
}
+ [TestMethod]
+ [DataRow(0, 0, 6)]
+ [DataRow(1.23, 2.34, 12)]
+ public void TryFormat_ComplexOfDoubleWithAdequateDestinationLength_ReturnsTrue(double inReal, double inImaginary, int length)
+ {
+ Complex z = new(inReal, inImaginary);
+
+ Span span = new char[length];
+ var actual = z.TryFormat(span, out int _, null, null);
+
+ Assert.IsTrue(actual);
+ }
+
+ [TestMethod]
+ [DataRow(0, 0, 5)]
+ [DataRow(1.23, 2.34, 11)]
+ public void TryFormat_ComplexOfDoubleWithInadequateDestinationLength_ReturnsFalse(double inReal, double inImaginary, int length)
+ {
+ Complex z = new(inReal, inImaginary);
+
+ Span span = new char[length];
+ var actual = z.TryFormat(span, out int _, null, null);
+
+ Assert.IsFalse(actual);
+ }
+
[TestMethod]
[DataRow(0, 0, 6, 6)]
[DataRow(1.23, 45.678, 14, 14)]
From ff736fb22817d812986ca40a039ee9fbe21f26d1 Mon Sep 17 00:00:00 2001
From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com>
Date: Tue, 12 Sep 2023 22:01:57 -0500
Subject: [PATCH 059/293] Update Precision.cs
- Add methods for comparing floating-point numbers
---
src/Mathematics.NET/Core/Precision.cs | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/src/Mathematics.NET/Core/Precision.cs b/src/Mathematics.NET/Core/Precision.cs
index 294bfa83..7089d3b7 100644
--- a/src/Mathematics.NET/Core/Precision.cs
+++ b/src/Mathematics.NET/Core/Precision.cs
@@ -43,4 +43,20 @@ public static class Precision
/// Machine epsilon for double-precision floating-point numbers according to the variant definition
public const double DblEpsilonVariant = 2.22044604925031308e-16;
+
+ public static bool AreApproximatelyEqual(T left, T right, T epsilon)
+ where T : IBinaryFloatingPointIeee754
+ => T.Abs(left - right) <= epsilon * T.Max(T.Abs(left), T.Abs(right));
+
+ public static bool AreEssentiallyEqual(T left, T right, T epsilon)
+ where T : IBinaryFloatingPointIeee754
+ => T.Abs(left - right) <= epsilon * T.Min(T.Abs(left), T.Abs(right));
+
+ public static bool IsDefinitelyGreaterThan(this T number, T value, T epsilon)
+ where T : IBinaryFloatingPointIeee754
+ => number - value > epsilon * T.Max(T.Abs(number), T.Abs(value));
+
+ public static bool IsDefinitelyLessThan(this T number, T value, T epsilon)
+ where T : IBinaryFloatingPointIeee754
+ => value - number > epsilon * T.Max(T.Abs(number), T.Abs(value));
}
From fc27f1e1f1211556531455fa3b0d7a6cb03ad14c Mon Sep 17 00:00:00 2001
From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com>
Date: Tue, 12 Sep 2023 22:43:07 -0500
Subject: [PATCH 060/293] Create PrecisionTests.cs
- Add tests for verifying floating-point equality methods
---
.../Core/PrecisionTests.cs | 61 +++++++++++++++++++
1 file changed, 61 insertions(+)
create mode 100644 tests/Mathematics.NET.Tests/Core/PrecisionTests.cs
diff --git a/tests/Mathematics.NET.Tests/Core/PrecisionTests.cs b/tests/Mathematics.NET.Tests/Core/PrecisionTests.cs
new file mode 100644
index 00000000..6395e45d
--- /dev/null
+++ b/tests/Mathematics.NET.Tests/Core/PrecisionTests.cs
@@ -0,0 +1,61 @@
+//
+// Mathematics.NET
+// https://github.com/HamletTanyavong/Mathematics.NET
+//
+// MIT License
+//
+// Copyright (c) 2023 Hamlet Tanyavong
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in all
+// copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+// SOFTWARE.
+//
+
+namespace Mathematics.NET.Tests.Core;
+
+[TestClass]
+[TestCategory("Core"), TestCategory("Precision")]
+public sealed class PrecisionTests
+{
+ [TestMethod]
+ [DataRow(1e-13, 1.0000000000000002e-13, Precision.DblEpsilonVariant, true)]
+ [DataRow(1e-13, 1.0000000000000004e-13, Precision.DblEpsilonVariant, false)]
+ [DataRow(1.0, 1.0000000000000002, Precision.DblEpsilonVariant, true)]
+ [DataRow(1.0, 1.0000000000000004, Precision.DblEpsilonVariant, false)]
+ [DataRow(1.23e27, 1.2300000000000002e27, Precision.DblEpsilonVariant, true)]
+ [DataRow(1.23e27, 1.2300000000000004e27, Precision.DblEpsilonVariant, false)]
+ public void AreApproximatelyEqual_TwoDoublePrecisionFloatingPointNumbers_ReturnsBool(double left, double right, double epsilon, bool expected)
+ {
+ var actual = Precision.AreApproximatelyEqual(left, right, epsilon);
+
+ Assert.AreEqual(expected, actual);
+ }
+
+ [TestMethod]
+ [DataRow(1e-13, 1.0000000000000002e-13, Precision.DblEpsilonVariant, true)]
+ [DataRow(1e-13, 1.0000000000000004e-13, Precision.DblEpsilonVariant, false)]
+ [DataRow(1.0, 1.0000000000000002, Precision.DblEpsilonVariant, true)]
+ [DataRow(1.0, 1.0000000000000004, Precision.DblEpsilonVariant, false)]
+ [DataRow(1.23e27, 1.2300000000000002e27, Precision.DblEpsilonVariant, true)]
+ [DataRow(1.23e27, 1.2300000000000004e27, Precision.DblEpsilonVariant, false)]
+ public void AreEssentiallyEqual_TwoDoublePrecisionFloatingPointNumbers_ReturnsBool(double left, double right, double epsilon, bool expected)
+ {
+ var actual = Precision.AreEssentiallyEqual(left, right, epsilon);
+
+ Assert.AreEqual(expected, actual);
+ }
+}
From 977f3ff5c0e0c89674d7f7b9cbc1cd126eac522d Mon Sep 17 00:00:00 2001
From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com>
Date: Wed, 13 Sep 2023 01:46:36 -0500
Subject: [PATCH 061/293] Create Constants.cs
---
src/Mathematics.NET/Core/Constants.cs | 63 +++++++++++++++++++++++++++
1 file changed, 63 insertions(+)
create mode 100644 src/Mathematics.NET/Core/Constants.cs
diff --git a/src/Mathematics.NET/Core/Constants.cs b/src/Mathematics.NET/Core/Constants.cs
new file mode 100644
index 00000000..a650eda8
--- /dev/null
+++ b/src/Mathematics.NET/Core/Constants.cs
@@ -0,0 +1,63 @@
+//
+// Mathematics.NET
+// https://github.com/HamletTanyavong/Mathematics.NET
+//
+// MIT License
+//
+// Copyright (c) 2023 Hamlet Tanyavong
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in all
+// copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+// SOFTWARE.
+//
+
+namespace Mathematics.NET.Core;
+
+/// Common mathematical constants
+public static class Constants
+{
+ /// Represents the natural logarithmic base, e
+ public const double E = 2.71828182845904523;
+ /// Represents the ratio of the circumference of a circle to its diameter, π
+ public const double Pi = 3.14159265358979323;
+ /// Represents π/2
+ public const double PiHalf = 1.57079632679489661;
+ /// Represents π squared
+ public const double PiSquared = 9.86960440108935861;
+ /// Represents 2π
+ public const double Tau = 6.28318530717958647;
+ /// Represents the Euler-Mascheroni constant, γ
+ public const double EulerMascheroni = 5.77215664901532860e-1;
+ /// Represents the golden ratio, φ
+ public const double GoldenRatio = 1.61803398874989484;
+ /// Represents the natural logarithm of 2
+ public const double Ln2 = 6.93147180559945309e-1;
+ /// Represents the natural logarithm of 3
+ public const double Ln3 = 1.09861228866810969;
+ /// Represents the natural logarithm of 4
+ public const double Ln4 = 1.38629436111989061;
+ /// Represents the natural logarithm of 5
+ public const double Ln5 = 1.60943791243410037;
+ /// Represents the natural logarithm of 10
+ public const double Ln10 = 2.30258509299404568;
+ /// Represents the square root of 2
+ public const double Sqrt2 = 1.41421356237309504;
+ /// Represents the square root of 3
+ public const double Sqrt3 = 1.73205080756887729;
+ /// Represents the square root of 5
+ public const double Sqrt5 = 2.23606797749978969;
+}
From 15694e49051de2de9b4fb00b3c678654787d643b Mon Sep 17 00:00:00 2001
From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com>
Date: Wed, 13 Sep 2023 11:12:02 -0500
Subject: [PATCH 062/293] Implement IEquatable interface
- Update IComplex interface
---
src/Mathematics.NET/Core/Complex.cs | 4 ++++
src/Mathematics.NET/Core/IComplex.cs | 1 +
src/Mathematics.NET/Core/Real.cs | 4 ++++
3 files changed, 9 insertions(+)
diff --git a/src/Mathematics.NET/Core/Complex.cs b/src/Mathematics.NET/Core/Complex.cs
index 4038cc91..73de6e38 100644
--- a/src/Mathematics.NET/Core/Complex.cs
+++ b/src/Mathematics.NET/Core/Complex.cs
@@ -88,6 +88,10 @@ public Complex(Real real, Real imaginary)
public static Complex Conjugate(Complex z) => new(z._real, -z._imaginary);
+ // Equality
+
+ public bool Equals(Complex value) => _real.Equals(value.Re) && _imaginary.Equals(value.Im);
+
// Formatting
public override string ToString() => ToString(null, null);
diff --git a/src/Mathematics.NET/Core/IComplex.cs b/src/Mathematics.NET/Core/IComplex.cs
index 9ce46fcd..6886b944 100644
--- a/src/Mathematics.NET/Core/IComplex.cs
+++ b/src/Mathematics.NET/Core/IComplex.cs
@@ -39,6 +39,7 @@ public interface IComplex
IDivisionOperation,
IMultiplicationOperation,
ISubtractionOperation,
+ IEquatable,
ISpanFormattable
where T : IComplex
where U : IFloatingPointIeee754
diff --git a/src/Mathematics.NET/Core/Real.cs b/src/Mathematics.NET/Core/Real.cs
index 140d9374..38a40348 100644
--- a/src/Mathematics.NET/Core/Real.cs
+++ b/src/Mathematics.NET/Core/Real.cs
@@ -74,6 +74,10 @@ public Real(T real)
public static Real Conjugate(Real x) => x;
+ // Equality
+
+ public bool Equals(Real value) => _value.Equals(value);
+
// Formatting
public override string ToString() => ToString(null, null);
From 4f4968354cbdf9a8ce463f27415107cfb2bb7061 Mon Sep 17 00:00:00 2001
From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com>
Date: Wed, 13 Sep 2023 11:19:53 -0500
Subject: [PATCH 063/293] Override Equals and GetHashCode
- Implement == and != operators
---
src/Mathematics.NET/Core/Complex.cs | 9 +++++++++
src/Mathematics.NET/Core/Real.cs | 9 +++++++++
2 files changed, 18 insertions(+)
diff --git a/src/Mathematics.NET/Core/Complex.cs b/src/Mathematics.NET/Core/Complex.cs
index 73de6e38..3cd04d8a 100644
--- a/src/Mathematics.NET/Core/Complex.cs
+++ b/src/Mathematics.NET/Core/Complex.cs
@@ -27,6 +27,7 @@
#pragma warning disable IDE0032
+using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Numerics;
@@ -90,8 +91,16 @@ public Complex(Real real, Real imaginary)
// Equality
+ public static bool operator ==(Complex left, Complex right) => left.Re == right.Re && left.Im == right.Im;
+
+ public static bool operator !=(Complex left, Complex right) => left.Re != right.Re || left.Im != right.Im;
+
+ public override bool Equals([NotNullWhen(true)] object? obj) => obj is Complex other && Equals(other);
+
public bool Equals(Complex value) => _real.Equals(value.Re) && _imaginary.Equals(value.Im);
+ public override int GetHashCode() => HashCode.Combine(_real, _imaginary);
+
// Formatting
public override string ToString() => ToString(null, null);
diff --git a/src/Mathematics.NET/Core/Real.cs b/src/Mathematics.NET/Core/Real.cs
index 38a40348..dadd970f 100644
--- a/src/Mathematics.NET/Core/Real.cs
+++ b/src/Mathematics.NET/Core/Real.cs
@@ -27,6 +27,7 @@
#pragma warning disable IDE0032
+using System.Diagnostics.CodeAnalysis;
using System.Numerics;
namespace Mathematics.NET.Core;
@@ -76,8 +77,16 @@ public Real(T real)
// Equality
+ public static bool operator ==(Real left, Real right) => left._value == right._value;
+
+ public static bool operator !=(Real left, Real right) => left._value != right._value;
+
+ public override bool Equals([NotNullWhen(true)] object? obj) => obj is Real other && Equals(other);
+
public bool Equals(Real value) => _value.Equals(value);
+ public override int GetHashCode() => HashCode.Combine(_value);
+
// Formatting
public override string ToString() => ToString(null, null);
From c972bd692237469ca37a9b65109bda58a83fa913 Mon Sep 17 00:00:00 2001
From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com>
Date: Wed, 13 Sep 2023 11:36:25 -0500
Subject: [PATCH 064/293] Use ToString
- Rename parameter
---
src/Mathematics.NET/Core/Complex.cs | 10 +++++-----
src/Mathematics.NET/Core/Real.cs | 2 +-
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/src/Mathematics.NET/Core/Complex.cs b/src/Mathematics.NET/Core/Complex.cs
index 3cd04d8a..6f2e0ab4 100644
--- a/src/Mathematics.NET/Core/Complex.cs
+++ b/src/Mathematics.NET/Core/Complex.cs
@@ -105,22 +105,22 @@ public Complex(Real real, Real imaginary)
public override string ToString() => ToString(null, null);
- public string ToString(string? format, IFormatProvider? formatProvider)
+ public string ToString(string? format, IFormatProvider? provider)
{
format = string.IsNullOrEmpty(format) ? "ALL" : format.ToUpperInvariant();
- formatProvider ??= NumberFormatInfo.InvariantInfo;
+ provider ??= NumberFormatInfo.InvariantInfo;
if (format is "ALL")
{
- return string.Format(formatProvider, "({0}, {1})", _real, _imaginary);
+ return string.Format(provider, "({0}, {1})", _real.ToString(null, provider), _imaginary.ToString(null, provider));
}
else if (format is "RE")
{
- return string.Format(formatProvider, "{0}", _real);
+ return string.Format(provider, "{0}", _real.ToString(null, provider));
}
else if (format is "IM")
{
- return string.Format(formatProvider, "{0}", _imaginary);
+ return string.Format(provider, "{0}", _imaginary.ToString(null, provider));
}
else
{
diff --git a/src/Mathematics.NET/Core/Real.cs b/src/Mathematics.NET/Core/Real.cs
index dadd970f..5221234a 100644
--- a/src/Mathematics.NET/Core/Real.cs
+++ b/src/Mathematics.NET/Core/Real.cs
@@ -91,7 +91,7 @@ public Real(T real)
public override string ToString() => ToString(null, null);
- public string ToString(string? format, IFormatProvider? formatProvider) => string.Format(formatProvider, "{0}", _value);
+ public string ToString(string? format, IFormatProvider? provider) => string.Format(provider, "{0}", _value.ToString(format, provider));
public bool TryFormat(Span