Skip to content

Commit 83545a2

Browse files
authored
Support System.Half (#30)
1 parent 4b54085 commit 83545a2

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

src/FSharp.UMX.fs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ open System
1818
#if NET6_0_OR_GREATER
1919
[<MeasureAnnotatedAbbreviation>] type DateOnly<[<Measure>] 'm> = DateOnly
2020
[<MeasureAnnotatedAbbreviation>] type TimeOnly<[<Measure>] 'm> = TimeOnly
21+
[<MeasureAnnotatedAbbreviation>] type Half<[<Measure>] 'm> = Half
2122
#endif
2223

2324
module private Unsafe =
@@ -47,6 +48,7 @@ type UMX =
4748
#if NET6_0_OR_GREATER
4849
static member inline tag<[<Measure>]'m> (x : DateOnly) : DateOnly<'m> = Unsafe.cast x
4950
static member inline tag<[<Measure>]'m> (x : TimeOnly) : TimeOnly<'m> = Unsafe.cast x
51+
static member inline tag<[<Measure>]'m> (x : Half) : Half<'m> = Unsafe.cast x
5052
#endif
5153

5254
static member inline untag<[<Measure>]'m> (x : bool<'m>) : bool = Unsafe.cast x
@@ -66,6 +68,7 @@ type UMX =
6668
#if NET6_0_OR_GREATER
6769
static member inline untag<[<Measure>]'m> (x : DateOnly<'m>) : DateOnly = Unsafe.cast x
6870
static member inline untag<[<Measure>]'m> (x : TimeOnly<'m>) : TimeOnly = Unsafe.cast x
71+
static member inline untag<[<Measure>]'m> (x : Half<'m>) : Half = Unsafe.cast x
6972
#endif
7073

7174
static member inline cast<[<Measure>]'m1, [<Measure>]'m2> (x : bool<'m1>) : bool<'m2> = Unsafe.cast x
@@ -85,6 +88,7 @@ type UMX =
8588
#if NET6_0_OR_GREATER
8689
static member inline cast<[<Measure>]'m1, [<Measure>]'m2> (x : DateOnly<'m1>) : DateOnly<'m2> = Unsafe.cast x
8790
static member inline cast<[<Measure>]'m1, [<Measure>]'m2> (x : TimeOnly<'m1>) : TimeOnly<'m2> = Unsafe.cast x
91+
static member inline cast<[<Measure>]'m1, [<Measure>]'m2> (x : Half<'m1>) : Half<'m2> = Unsafe.cast x
8892
#endif
8993

9094

tests/FSharp.UMX.Tests.fs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ let ``Simple unit of measure conversions``() =
2323
let y = (UMX.untag x).ToString("N") |> UMX.tag<skuId>
2424
let z = UMX.tag<km> 42
2525
let f = UMX.tag<km> 10.0f
26+
let h = UMX.tag<km> Half.MinValue
2627
let w = sprintf "%O %s %d %f" (UMX.untag x) (UMX.untag y) z f
2728
()
2829

@@ -35,6 +36,7 @@ let ``Simple unit of measure conversions with cast operator``() =
3536
let b : byte<foo> = % 1uy
3637
let s : int16<foo> = % 1s
3738
let f : float32<foo> = % 10.0f
39+
let h : Half<foo> = % Half.MaxValue
3840
let d : DateTime<foo> = % DateTime.Now
3941
let don : DateOnly<foo> = % DateOnly.FromDateTime(DateTime.Now)
4042
let ton : TimeOnly<foo> = % TimeOnly.FromDateTime(DateTime.Now)
@@ -50,6 +52,7 @@ let ``Simple unit of measure conversions with UMX.tag function``() =
5052
let s = UMX.tag<foo> (1s)
5153
let f = UMX.tag<foo> (10.0f)
5254
let d = UMX.tag<foo> DateTime.Now
55+
let h = UMX.tag<foo> Half.Epsilon
5356
let don = UMX.tag<foo> (DateOnly.FromDateTime(DateTime.Now))
5457
let ton = UMX.tag<foo> (TimeOnly.FromDateTime(DateTime.Now))
5558
()

0 commit comments

Comments
 (0)