Skip to content

Instantly share code, notes, and snippets.

@micampbell
micampbell / Square Root of Int128 c#
Last active December 12, 2024 01:02
A method to find the square root of Int128 without any fancy under the hood stuff
/// <summary>
/// There currently is no method in C# to take the square root of an Int128.
/// However, we occasionally need to do this. This method finds the integer
/// component of the square root - as if you did a Floor function on the
/// actual square root.
/// </summary>
/// <param name="num"></param>
/// <returns></returns>
internal static Int128 SquareRoot(Int128 num)
{
@micampbell
micampbell / Levenberg-Marquadt-Optimization.cs
Last active May 29, 2022 22:18
The Levenberg-Marquadt Optimization can be used in many ways. It is often used to fit data where the objective function is the squared difference between predicted value and each data point.
using System;
using System.Linq;
using System.Runtime.CompilerServices;
namespace LMOpt
{
/// <summary>
/// Class Levenberg-Marquadt Optimization. This class includes functions to run this optimization method.
/// It is an abstract class, so you must inherit it in A new class. That new class must have the following:
/// 1. A constructor that calls the base constructor