mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-07-31 02:47:44 +00:00
8cec2fec8d
fix: Update condition checks in Htit and Mgdi for better numerical stability refactor: Simplify parameter struct in T3 and enhance Vidya state management
29 lines
971 B
C#
29 lines
971 B
C#
using System.Runtime.CompilerServices;
|
|
|
|
namespace QuanTAlib;
|
|
|
|
/// <summary>
|
|
/// A lightweight struct representing a time-value pair.
|
|
/// Pure data type: 16 bytes (long + double).
|
|
/// </summary>
|
|
[SkipLocalsInit]
|
|
public readonly record struct TValue(long Time, double Value)
|
|
{
|
|
public DateTime AsDateTime => new(Time, DateTimeKind.Utc);
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public TValue(DateTime time, double value)
|
|
: this(time.Kind == DateTimeKind.Utc ? time.Ticks : time.ToUniversalTime().Ticks, value)
|
|
{
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static implicit operator double(TValue tv) => tv.Value;
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static implicit operator DateTime(TValue tv) => new(tv.Time, DateTimeKind.Utc);
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public override string ToString() => $"[{AsDateTime:yyyy-MM-dd HH:mm:ss}, {Value:F2}]";
|
|
}
|