/
NFloat.cs
1922 lines (1646 loc) · 104 KB
/
NFloat.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Buffers.Binary;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
#pragma warning disable SA1121 // We use our own aliases since they differ per platform
#if TARGET_32BIT
using NativeExponentType = System.SByte;
using NativeSignificandType = System.UInt32;
using NativeType = System.Single;
#else
using NativeExponentType = System.Int16;
using NativeSignificandType = System.UInt64;
using NativeType = System.Double;
#endif
namespace System.Runtime.InteropServices
{
/// <summary>Defines an immutable value type that represents a floating type that has the same size as the native integer size.</summary>
/// <remarks>It is meant to be used as an exchange type at the managed/unmanaged boundary to accurately represent in managed code unmanaged APIs that use a type alias for C or C++'s <c>float</c> on 32-bit platforms or <c>double</c> on 64-bit platforms, such as the CGFloat type in libraries provided by Apple.</remarks>
[Intrinsic]
[NonVersionable] // This only applies to field layout
public readonly struct NFloat
: IBinaryFloatingPointIeee754<NFloat>,
IMinMaxValue<NFloat>,
IUtf8SpanFormattable
{
private const NumberStyles DefaultNumberStyles = NumberStyles.Float | NumberStyles.AllowThousands;
private readonly NativeType _value;
/// <summary>Constructs an instance from a 32-bit floating point value.</summary>
/// <param name="value">The floating-point value.</param>
[NonVersionable]
public NFloat(float value)
{
_value = value;
}
/// <summary>Constructs an instance from a 64-bit floating point value.</summary>
/// <param name="value">The floating-point value.</param>
[NonVersionable]
public NFloat(double value)
{
_value = (NativeType)value;
}
/// <summary>Represents the smallest positive NFloat value that is greater than zero.</summary>
public static NFloat Epsilon
{
[NonVersionable]
get => new NFloat(NativeType.Epsilon);
}
/// <summary>Represents the largest finite value of a NFloat.</summary>
public static NFloat MaxValue
{
[NonVersionable]
get => new NFloat(NativeType.MaxValue);
}
/// <summary>Represents the smallest finite value of a NFloat.</summary>
public static NFloat MinValue
{
[NonVersionable]
get => new NFloat(NativeType.MinValue);
}
/// <summary>Represents a value that is not a number (NaN).</summary>
public static NFloat NaN
{
[NonVersionable]
get => new NFloat(NativeType.NaN);
}
/// <summary>Represents negative infinity.</summary>
public static NFloat NegativeInfinity
{
[NonVersionable]
get => new NFloat(NativeType.NegativeInfinity);
}
/// <summary>Represents positive infinity.</summary>
public static NFloat PositiveInfinity
{
[NonVersionable]
get => new NFloat(NativeType.PositiveInfinity);
}
/// <summary>Gets the size, in bytes, of an NFloat.</summary>
public static int Size
{
[NonVersionable]
get => sizeof(NativeType);
}
/// <summary>The underlying floating-point value of this instance.</summary>
public double Value
{
[NonVersionable]
get => _value;
}
//
// Unary Arithmetic
//
/// <summary>Computes the unary plus of a value.</summary>
/// <param name="value">The value for which to compute its unary plus.</param>
/// <returns>The unary plus of <paramref name="value" />.</returns>
[NonVersionable]
public static NFloat operator +(NFloat value) => value;
/// <summary>Computes the unary negation of a value.</summary>
/// <param name="value">The value for which to compute its unary negation.</param>
/// <returns>The unary negation of <paramref name="value" />.</returns>
[NonVersionable]
public static NFloat operator -(NFloat value) => new NFloat(-value._value);
/// <summary>Increments a value.</summary>
/// <param name="value">The value to increment.</param>
/// <returns>The result of incrementing <paramref name="value" />.</returns>
[NonVersionable]
public static NFloat operator ++(NFloat value)
{
NativeType tmp = value._value;
++tmp;
return new NFloat(tmp);
}
/// <summary>Decrements a value.</summary>
/// <param name="value">The value to decrement.</param>
/// <returns>The result of decrementing <paramref name="value" />.</returns>
[NonVersionable]
public static NFloat operator --(NFloat value)
{
NativeType tmp = value._value;
--tmp;
return new NFloat(tmp);
}
//
// Binary Arithmetic
//
/// <summary>Adds two values together to compute their sum.</summary>
/// <param name="left">The value to which <paramref name="right" /> is added.</param>
/// <param name="right">The value which is added to <paramref name="left" />.</param>
/// <returns>The sum of <paramref name="left" /> and <paramref name="right" />.</returns>
[NonVersionable]
public static NFloat operator +(NFloat left, NFloat right) => new NFloat(left._value + right._value);
/// <summary>Subtracts two values to compute their difference.</summary>
/// <param name="left">The value from which <paramref name="right" /> is subtracted.</param>
/// <param name="right">The value which is subtracted from <paramref name="left" />.</param>
/// <returns>The difference of <paramref name="right" /> subtracted from <paramref name="left" />.</returns>
[NonVersionable]
public static NFloat operator -(NFloat left, NFloat right) => new NFloat(left._value - right._value);
/// <summary>Multiplies two values together to compute their product.</summary>
/// <param name="left">The value which <paramref name="right" /> multiplies.</param>
/// <param name="right">The value which multiplies <paramref name="left" />.</param>
/// <returns>The product of <paramref name="left" /> multiplied-by <paramref name="right" />.</returns>
[NonVersionable]
public static NFloat operator *(NFloat left, NFloat right) => new NFloat(left._value * right._value);
/// <summary>Divides two values together to compute their quotient.</summary>
/// <param name="left">The value which <paramref name="right" /> divides.</param>
/// <param name="right">The value which divides <paramref name="left" />.</param>
/// <returns>The quotient of <paramref name="left" /> divided-by <paramref name="right" />.</returns>
[NonVersionable]
public static NFloat operator /(NFloat left, NFloat right) => new NFloat(left._value / right._value);
/// <summary>Divides two values together to compute their remainder.</summary>
/// <param name="left">The value which <paramref name="right" /> divides.</param>
/// <param name="right">The value which divides <paramref name="left" />.</param>
/// <returns>The remainder of <paramref name="left" /> divided-by <paramref name="right" />.</returns>
[NonVersionable]
public static NFloat operator %(NFloat left, NFloat right) => new NFloat(left._value % right._value);
//
// Comparisons
//
/// <summary>Compares two values to determine equality.</summary>
/// <param name="left">The value to compare with <paramref name="right" />.</param>
/// <param name="right">The value to compare with <paramref name="left" />.</param>
/// <returns><c>true</c> if <paramref name="left" /> is equal to <paramref name="right" />; otherwise, <c>false</c>.</returns>
[NonVersionable]
public static bool operator ==(NFloat left, NFloat right) => left._value == right._value;
/// <summary>Compares two values to determine inequality.</summary>
/// <param name="left">The value to compare with <paramref name="right" />.</param>
/// <param name="right">The value to compare with <paramref name="left" />.</param>
/// <returns><c>true</c> if <paramref name="left" /> is not equal to <paramref name="right" />; otherwise, <c>false</c>.</returns>
[NonVersionable]
public static bool operator !=(NFloat left, NFloat right) => left._value != right._value;
/// <summary>Compares two values to determine which is less.</summary>
/// <param name="left">The value to compare with <paramref name="right" />.</param>
/// <param name="right">The value to compare with <paramref name="left" />.</param>
/// <returns><c>true</c> if <paramref name="left" /> is less than <paramref name="right" />; otherwise, <c>false</c>.</returns>
[NonVersionable]
public static bool operator <(NFloat left, NFloat right) => left._value < right._value;
/// <summary>Compares two values to determine which is less or equal.</summary>
/// <param name="left">The value to compare with <paramref name="right" />.</param>
/// <param name="right">The value to compare with <paramref name="left" />.</param>
/// <returns><c>true</c> if <paramref name="left" /> is less than or equal to <paramref name="right" />; otherwise, <c>false</c>.</returns>
[NonVersionable]
public static bool operator <=(NFloat left, NFloat right) => left._value <= right._value;
/// <summary>Compares two values to determine which is greater.</summary>
/// <param name="left">The value to compare with <paramref name="right" />.</param>
/// <param name="right">The value to compare with <paramref name="left" />.</param>
/// <returns><c>true</c> if <paramref name="left" /> is greater than <paramref name="right" />; otherwise, <c>false</c>.</returns>
[NonVersionable]
public static bool operator >(NFloat left, NFloat right) => left._value > right._value;
/// <summary>Compares two values to determine which is greater or equal.</summary>
/// <param name="left">The value to compare with <paramref name="right" />.</param>
/// <param name="right">The value to compare with <paramref name="left" />.</param>
/// <returns><c>true</c> if <paramref name="left" /> is greater than or equal to <paramref name="right" />; otherwise, <c>false</c>.</returns>
[NonVersionable]
public static bool operator >=(NFloat left, NFloat right) => left._value >= right._value;
//
// Explicit Convert To NFloat
//
/// <summary>Explicitly converts a <see cref="decimal" /> value to its nearest representable native-sized floating-point value.</summary>
/// <param name="value">The value to convert.</param>
/// <returns><paramref name="value" /> converted to its nearest representable native-sized floating-point value.</returns>
[NonVersionable]
public static explicit operator NFloat(decimal value) => new NFloat((NativeType)value);
/// <summary>Explicitly converts a <see cref="double" /> value to its nearest representable native-sized floating-point value.</summary>
/// <param name="value">The value to convert.</param>
/// <returns><paramref name="value" /> converted to its nearest representable native-sized floating-point value.</returns>
[NonVersionable]
public static explicit operator NFloat(double value) => new NFloat((NativeType)value);
//
// Explicit Convert From NFloat
//
/// <summary>Explicitly converts a native-sized floating-point value to its nearest representable <see cref="byte" /> value.</summary>
/// <param name="value">The value to convert.</param>
/// <returns><paramref name="value" /> converted to its nearest representable <see cref="byte" /> value.</returns>
[NonVersionable]
public static explicit operator byte(NFloat value) => (byte)(value._value);
/// <summary>Explicitly converts a native-sized floating-point value to its nearest representable <see cref="byte" /> value, throwing an overflow exception for any values that fall outside the representable range.</summary>
/// <param name="value">The value to convert.</param>
/// <returns><paramref name="value" /> converted to its nearest representable <see cref="byte" /> value.</returns>
/// <exception cref="OverflowException"><paramref name="value" /> is not representable by <see cref="byte" />.</exception>
[NonVersionable]
public static explicit operator checked byte(NFloat value) => checked((byte)(value._value));
/// <summary>Explicitly converts a native-sized floating-point value to its nearest representable <see cref="char" /> value.</summary>
/// <param name="value">The value to convert.</param>
/// <returns><paramref name="value" /> converted to its nearest representable <see cref="char" /> value.</returns>
[NonVersionable]
public static explicit operator char(NFloat value) => (char)(value._value);
/// <summary>Explicitly converts a native-sized floating-point value to its nearest representable <see cref="char" /> value, throwing an overflow exception for any values that fall outside the representable range.</summary>
/// <param name="value">The value to convert.</param>
/// <returns><paramref name="value" /> converted to its nearest representable <see cref="char" /> value.</returns>
/// <exception cref="OverflowException"><paramref name="value" /> is not representable by <see cref="char" />.</exception>
[NonVersionable]
public static explicit operator checked char(NFloat value) => checked((char)(value._value));
/// <summary>Explicitly converts a native-sized floating-point value to its nearest representable <see cref="decimal" /> value.</summary>
/// <param name="value">The value to convert.</param>
/// <returns><paramref name="value" /> converted to its nearest representable <see cref="decimal" /> value.</returns>
[NonVersionable]
public static explicit operator decimal(NFloat value) => (decimal)(value._value);
/// <summary>Explicitly converts a native-sized floating-point value to its nearest representable <see cref="Half" /> value.</summary>
/// <param name="value">The value to convert.</param>
/// <returns><paramref name="value" /> converted to its nearest representable <see cref="Half" /> value.</returns>
[NonVersionable]
public static explicit operator Half(NFloat value) => (Half)(value._value);
/// <summary>Explicitly converts a native-sized floating-point value to its nearest representable <see cref="short" /> value.</summary>
/// <param name="value">The value to convert.</param>
/// <returns><paramref name="value" /> converted to its nearest representable <see cref="short" /> value.</returns>
[NonVersionable]
public static explicit operator short(NFloat value) => (short)(value._value);
/// <summary>Explicitly converts a native-sized floating-point value to its nearest representable <see cref="short" /> value, throwing an overflow exception for any values that fall outside the representable range.</summary>
/// <param name="value">The value to convert.</param>
/// <returns><paramref name="value" /> converted to its nearest representable <see cref="short" /> value.</returns>
/// <exception cref="OverflowException"><paramref name="value" /> is not representable by <see cref="short" />.</exception>
[NonVersionable]
public static explicit operator checked short(NFloat value) => checked((short)(value._value));
/// <summary>Explicitly converts a native-sized floating-point value to its nearest representable <see cref="int" /> value.</summary>
/// <param name="value">The value to convert.</param>
/// <returns><paramref name="value" /> converted to its nearest representable <see cref="int" /> value.</returns>
[NonVersionable]
public static explicit operator int(NFloat value) => (int)(value._value);
/// <summary>Explicitly converts a native-sized floating-point value to its nearest representable <see cref="int" /> value, throwing an overflow exception for any values that fall outside the representable range.</summary>
/// <param name="value">The value to convert.</param>
/// <returns><paramref name="value" /> converted to its nearest representable <see cref="int" /> value.</returns>
/// <exception cref="OverflowException"><paramref name="value" /> is not representable by <see cref="int" />.</exception>
[NonVersionable]
public static explicit operator checked int(NFloat value) => checked((int)(value._value));
/// <summary>Explicitly converts a native-sized floating-point value to its nearest representable <see cref="long" /> value.</summary>
/// <param name="value">The value to convert.</param>
/// <returns><paramref name="value" /> converted to its nearest representable <see cref="long" /> value.</returns>
[NonVersionable]
public static explicit operator long(NFloat value) => (long)(value._value);
/// <summary>Explicitly converts a native-sized floating-point value to its nearest representable <see cref="long" /> value, throwing an overflow exception for any values that fall outside the representable range.</summary>
/// <param name="value">The value to convert.</param>
/// <returns><paramref name="value" /> converted to its nearest representable <see cref="long" /> value.</returns>
/// <exception cref="OverflowException"><paramref name="value" /> is not representable by <see cref="long" />.</exception>
[NonVersionable]
public static explicit operator checked long(NFloat value) => checked((long)(value._value));
/// <summary>Explicitly converts a native-sized floating-point value to its nearest representable <see cref="Int128" /> value.</summary>
/// <param name="value">The value to convert.</param>
/// <returns><paramref name="value" /> converted to its nearest representable <see cref="Int128" /> value.</returns>
[NonVersionable]
public static explicit operator Int128(NFloat value) => (Int128)(value._value);
/// <summary>Explicitly converts a native-sized floating-point value to its nearest representable <see cref="Int128" /> value, throwing an overflow exception for any values that fall outside the representable range.</summary>
/// <param name="value">The value to convert.</param>
/// <returns><paramref name="value" /> converted to its nearest representable <see cref="Int128" /> value.</returns>
/// <exception cref="OverflowException"><paramref name="value" /> is not representable by <see cref="Int128" />.</exception>
[NonVersionable]
public static explicit operator checked Int128(NFloat value) => checked((Int128)(value._value));
/// <summary>Explicitly converts a native-sized floating-point value to its nearest representable <see cref="IntPtr" /> value.</summary>
/// <param name="value">The value to convert.</param>
/// <returns><paramref name="value" /> converted to its nearest representable <see cref="IntPtr" /> value.</returns>
[NonVersionable]
public static explicit operator nint(NFloat value) => (nint)(value._value);
/// <summary>Explicitly converts a native-sized floating-point value to its nearest representable <see cref="IntPtr" /> value, throwing an overflow exception for any values that fall outside the representable range.</summary>
/// <param name="value">The value to convert.</param>
/// <returns><paramref name="value" /> converted to its nearest representable <see cref="IntPtr" /> value.</returns>
/// <exception cref="OverflowException"><paramref name="value" /> is not representable by <see cref="IntPtr" />.</exception>
[NonVersionable]
public static explicit operator checked nint(NFloat value) => checked((nint)(value._value));
/// <summary>Explicitly converts a native-sized floating-point value to its nearest representable <see cref="sbyte" /> value.</summary>
/// <param name="value">The value to convert.</param>
/// <returns><paramref name="value" /> converted to its nearest representable <see cref="sbyte" /> value.</returns>
[NonVersionable]
[CLSCompliant(false)]
public static explicit operator sbyte(NFloat value) => (sbyte)(value._value);
/// <summary>Explicitly converts a native-sized floating-point value to its nearest representable <see cref="sbyte" /> value, throwing an overflow exception for any values that fall outside the representable range.</summary>
/// <param name="value">The value to convert.</param>
/// <returns><paramref name="value" /> converted to its nearest representable <see cref="sbyte" /> value.</returns>
/// <exception cref="OverflowException"><paramref name="value" /> is not representable by <see cref="sbyte" />.</exception>
[NonVersionable]
[CLSCompliant(false)]
public static explicit operator checked sbyte(NFloat value) => checked((sbyte)(value._value));
/// <summary>Explicitly converts a native-sized floating-point value to its nearest representable <see cref="float" /> value.</summary>
/// <param name="value">The value to convert.</param>
/// <returns><paramref name="value" /> converted to its nearest representable <see cref="float" /> value.</returns>
[NonVersionable]
public static explicit operator float(NFloat value) => (float)(value._value);
/// <summary>Explicitly converts a native-sized floating-point value to its nearest representable <see cref="ushort" /> value.</summary>
/// <param name="value">The value to convert.</param>
/// <returns><paramref name="value" /> converted to its nearest representable <see cref="ushort" /> value.</returns>
[NonVersionable]
[CLSCompliant(false)]
public static explicit operator ushort(NFloat value) => (ushort)(value._value);
/// <summary>Explicitly converts a native-sized floating-point value to its nearest representable <see cref="ushort" /> value, throwing an overflow exception for any values that fall outside the representable range.</summary>
/// <param name="value">The value to convert.</param>
/// <returns><paramref name="value" /> converted to its nearest representable <see cref="ushort" /> value.</returns>
/// <exception cref="OverflowException"><paramref name="value" /> is not representable by <see cref="ushort" />.</exception>
[NonVersionable]
[CLSCompliant(false)]
public static explicit operator checked ushort(NFloat value) => checked((ushort)(value._value));
/// <summary>Explicitly converts a native-sized floating-point value to its nearest representable <see cref="uint" /> value.</summary>
/// <param name="value">The value to convert.</param>
/// <returns><paramref name="value" /> converted to its nearest representable <see cref="uint" /> value.</returns>
[NonVersionable]
[CLSCompliant(false)]
public static explicit operator uint(NFloat value) => (uint)(value._value);
/// <summary>Explicitly converts a native-sized floating-point value to its nearest representable <see cref="uint" /> value, throwing an overflow exception for any values that fall outside the representable range.</summary>
/// <param name="value">The value to convert.</param>
/// <returns><paramref name="value" /> converted to its nearest representable <see cref="uint" /> value.</returns>
/// <exception cref="OverflowException"><paramref name="value" /> is not representable by <see cref="uint" />.</exception>
[NonVersionable]
[CLSCompliant(false)]
public static explicit operator checked uint(NFloat value) => checked((uint)(value._value));
/// <summary>Explicitly converts a native-sized floating-point value to its nearest representable <see cref="ulong" /> value.</summary>
/// <param name="value">The value to convert.</param>
/// <returns><paramref name="value" /> converted to its nearest representable <see cref="ulong" /> value.</returns>
[NonVersionable]
[CLSCompliant(false)]
public static explicit operator ulong(NFloat value) => (ulong)(value._value);
/// <summary>Explicitly converts a native-sized floating-point value to its nearest representable <see cref="ulong" /> value, throwing an overflow exception for any values that fall outside the representable range.</summary>
/// <param name="value">The value to convert.</param>
/// <returns><paramref name="value" /> converted to its nearest representable <see cref="ulong" /> value.</returns>
/// <exception cref="OverflowException"><paramref name="value" /> is not representable by <see cref="ulong" />.</exception>
[NonVersionable]
[CLSCompliant(false)]
public static explicit operator checked ulong(NFloat value) => checked((ulong)(value._value));
/// <summary>Explicitly converts a native-sized floating-point value to its nearest representable <see cref="UInt128" /> value.</summary>
/// <param name="value">The value to convert.</param>
/// <returns><paramref name="value" /> converted to its nearest representable <see cref="UInt128" /> value.</returns>
[NonVersionable]
[CLSCompliant(false)]
public static explicit operator UInt128(NFloat value) => (UInt128)(value._value);
/// <summary>Explicitly converts a native-sized floating-point value to its nearest representable <see cref="UInt128" /> value, throwing an overflow exception for any values that fall outside the representable range.</summary>
/// <param name="value">The value to convert.</param>
/// <returns><paramref name="value" /> converted to its nearest representable <see cref="UInt128" /> value.</returns>
/// <exception cref="OverflowException"><paramref name="value" /> is not representable by <see cref="UInt128" />.</exception>
[NonVersionable]
[CLSCompliant(false)]
public static explicit operator checked UInt128(NFloat value) => checked((UInt128)(value._value));
/// <summary>Explicitly converts a native-sized floating-point value to its nearest representable <see cref="UIntPtr" /> value.</summary>
/// <param name="value">The value to convert.</param>
/// <returns><paramref name="value" /> converted to its nearest representable <see cref="UIntPtr" /> value.</returns>
[NonVersionable]
[CLSCompliant(false)]
public static explicit operator nuint(NFloat value) => (nuint)(value._value);
/// <summary>Explicitly converts a native-sized floating-point value to its nearest representable <see cref="UIntPtr" /> value, throwing an overflow exception for any values that fall outside the representable range.</summary>
/// <param name="value">The value to convert.</param>
/// <returns><paramref name="value" /> converted to its nearest representable <see cref="UIntPtr" /> value.</returns>
/// <exception cref="OverflowException"><paramref name="value" /> is not representable by <see cref="UIntPtr" />.</exception>
[NonVersionable]
[CLSCompliant(false)]
public static explicit operator checked nuint(NFloat value) => checked((nuint)(value._value));
//
// Implicit Convert To NFloat
//
/// <summary>Implicitly converts a <see cref="byte" /> value to its nearest representable native-sized floating-point value.</summary>
/// <param name="value">The value to convert.</param>
/// <returns><paramref name="value" /> converted to its nearest representable native-sized floating-point value.</returns>
[NonVersionable]
public static implicit operator NFloat(byte value) => new NFloat((NativeType)value);
/// <summary>Implicitly converts a <see cref="char" /> value to its nearest representable native-sized floating-point value.</summary>
/// <param name="value">The value to convert.</param>
/// <returns><paramref name="value" /> converted to its nearest representable native-sized floating-point value.</returns>
[NonVersionable]
public static implicit operator NFloat(char value) => new NFloat((NativeType)value);
/// <summary>Implicitly converts a <see cref="Half" /> value to its nearest representable native-sized floating-point value.</summary>
/// <param name="value">The value to convert.</param>
/// <returns><paramref name="value" /> converted to its nearest representable native-sized floating-point value.</returns>
[NonVersionable]
public static implicit operator NFloat(Half value) => (NFloat)(float)value;
/// <summary>Implicitly converts a <see cref="short" /> value to its nearest representable native-sized floating-point value.</summary>
/// <param name="value">The value to convert.</param>
/// <returns><paramref name="value" /> converted to its nearest representable native-sized floating-point value.</returns>
[NonVersionable]
public static implicit operator NFloat(short value) => new NFloat((NativeType)value);
/// <summary>Implicitly converts a <see cref="int" /> value to its nearest representable native-sized floating-point value.</summary>
/// <param name="value">The value to convert.</param>
/// <returns><paramref name="value" /> converted to its nearest representable native-sized floating-point value.</returns>
[NonVersionable]
public static implicit operator NFloat(int value) => new NFloat((NativeType)value);
/// <summary>Implicitly converts a <see cref="long" /> value to its nearest representable native-sized floating-point value.</summary>
/// <param name="value">The value to convert.</param>
/// <returns><paramref name="value" /> converted to its nearest representable native-sized floating-point value.</returns>
[NonVersionable]
public static implicit operator NFloat(long value) => new NFloat((NativeType)value);
/// <summary>Explicitly converts a <see cref="Int128" /> to its nearest representable native-sized floating-point value.</summary>
/// <param name="value">The value to convert.</param>
/// <returns><paramref name="value" /> converted to its nearest representable native-sized floating-point value.</returns>
[NonVersionable]
public static explicit operator NFloat(Int128 value)
{
if (Int128.IsNegative(value))
{
value = -value;
return -(NFloat)(UInt128)(value);
}
return (NFloat)(UInt128)(value);
}
/// <summary>Implicitly converts a <see cref="System.IntPtr" /> value to its nearest representable native-sized floating-point value.</summary>
/// <param name="value">The value to convert.</param>
/// <returns><paramref name="value" /> converted to its nearest representable native-sized floating-point value.</returns>
[NonVersionable]
public static implicit operator NFloat(nint value) => new NFloat((NativeType)value);
/// <summary>Implicitly converts a <see cref="sbyte" /> value to its nearest representable native-sized floating-point value.</summary>
/// <param name="value">The value to convert.</param>
/// <returns><paramref name="value" /> converted to its nearest representable native-sized floating-point value.</returns>
[NonVersionable]
[CLSCompliant(false)]
public static implicit operator NFloat(sbyte value) => new NFloat((NativeType)value);
/// <summary>Implicitly converts a <see cref="float" /> value to its nearest representable native-sized floating-point value.</summary>
/// <param name="value">The value to convert.</param>
/// <returns><paramref name="value" /> converted to its nearest representable native-sized floating-point value.</returns>
[NonVersionable]
public static implicit operator NFloat(float value) => new NFloat((NativeType)value);
/// <summary>Implicitly converts a <see cref="ushort" /> value to its nearest representable native-sized floating-point value.</summary>
/// <param name="value">The value to convert.</param>
/// <returns><paramref name="value" /> converted to its nearest representable native-sized floating-point value.</returns>
[NonVersionable]
[CLSCompliant(false)]
public static implicit operator NFloat(ushort value) => new NFloat((NativeType)value);
/// <summary>Implicitly converts a <see cref="uint" /> value to its nearest representable native-sized floating-point value.</summary>
/// <param name="value">The value to convert.</param>
/// <returns><paramref name="value" /> converted to its nearest representable native-sized floating-point value.</returns>
[NonVersionable]
[CLSCompliant(false)]
public static implicit operator NFloat(uint value) => new NFloat((NativeType)value);
/// <summary>Implicitly converts a <see cref="ulong" /> value to its nearest representable native-sized floating-point value.</summary>
/// <param name="value">The value to convert.</param>
/// <returns><paramref name="value" /> converted to its nearest representable native-sized floating-point value.</returns>
[NonVersionable]
[CLSCompliant(false)]
public static implicit operator NFloat(ulong value) => new NFloat((NativeType)value);
/// <summary>Explicitly converts <see cref="UInt128"/> to its nearest representable native-sized floating-point value.</summary>
/// <param name="value">The value to convert.</param>
/// <returns><paramref name="value" /> converted to its nearest representable native-sized floating-point value.</returns>
[NonVersionable]
[CLSCompliant(false)]
public static explicit operator NFloat(UInt128 value) => (NFloat)(double)(value);
/// <summary>Implicitly converts a <see cref="System.UIntPtr" /> value to its nearest representable native-sized floating-point value.</summary>
/// <param name="value">The value to convert.</param>
/// <returns><paramref name="value" /> converted to its nearest representable native-sized floating-point value.</returns>
[NonVersionable]
[CLSCompliant(false)]
public static implicit operator NFloat(nuint value) => new NFloat((NativeType)value);
//
// Implicit Convert From NFloat
//
/// <summary>Implicitly converts a native-sized floating-point value to its nearest representable <see cref="double" /> value.</summary>
/// <param name="value">The value to convert.</param>
/// <returns><paramref name="value" /> converted to its nearest representable <see cref="double" /> value.</returns>
public static implicit operator double(NFloat value) => (double)(value._value);
/// <summary>Determines whether the specified value is finite (zero, subnormal, or normal).</summary>
/// <param name="value">The floating-point value.</param>
/// <returns><c>true</c> if the value is finite (zero, subnormal or normal); <c>false</c> otherwise.</returns>
[NonVersionable]
public static bool IsFinite(NFloat value) => NativeType.IsFinite(value._value);
/// <summary>Determines whether the specified value is infinite (positive or negative infinity).</summary>
/// <param name="value">The floating-point value.</param>
/// <returns><c>true</c> if the value is infinite (positive or negative infinity); <c>false</c> otherwise.</returns>
[NonVersionable]
public static bool IsInfinity(NFloat value) => NativeType.IsInfinity(value._value);
/// <summary>Determines whether the specified value is NaN (not a number).</summary>
/// <param name="value">The floating-point value.</param>
/// <returns><c>true</c> if the value is NaN (not a number); <c>false</c> otherwise.</returns>
[NonVersionable]
public static bool IsNaN(NFloat value) => NativeType.IsNaN(value._value);
/// <summary>Determines whether the specified value is negative.</summary>
/// <param name="value">The floating-point value.</param>
/// <returns><c>true</c> if the value is negative; <c>false</c> otherwise.</returns>
[NonVersionable]
public static bool IsNegative(NFloat value) => NativeType.IsNegative(value._value);
/// <summary>Determines whether the specified value is negative infinity.</summary>
/// <param name="value">The floating-point value.</param>
/// <returns><c>true</c> if the value is negative infinity; <c>false</c> otherwise.</returns>
[NonVersionable]
public static bool IsNegativeInfinity(NFloat value) => NativeType.IsNegativeInfinity(value._value);
/// <summary>Determines whether the specified value is normal.</summary>
/// <param name="value">The floating-point value.</param>
/// <returns><c>true</c> if the value is normal; <c>false</c> otherwise.</returns>
[NonVersionable]
public static bool IsNormal(NFloat value) => NativeType.IsNormal(value._value);
/// <summary>Determines whether the specified value is positive infinity.</summary>
/// <param name="value">The floating-point value.</param>
/// <returns><c>true</c> if the value is positive infinity; <c>false</c> otherwise.</returns>
[NonVersionable]
public static bool IsPositiveInfinity(NFloat value) => NativeType.IsPositiveInfinity(value._value);
/// <summary>Determines whether the specified value is subnormal.</summary>
/// <param name="value">The floating-point value.</param>
/// <returns><c>true</c> if the value is subnormal; <c>false</c> otherwise.</returns>
[NonVersionable]
public static bool IsSubnormal(NFloat value) => NativeType.IsSubnormal(value._value);
/// <summary>Converts the string representation of a number to its floating-point number equivalent.</summary>
/// <param name="s">A string that contains the number to convert.</param>
/// <returns>A floating-point number that is equivalent to the numeric value or symbol specified in <paramref name="s" />.</returns>
/// <exception cref="ArgumentNullException"><paramref name="s" /> is <c>null</c>.</exception>
/// <exception cref="FormatException"><paramref name="s" /> does not represent a number in a valid format.</exception>
public static NFloat Parse(string s)
{
var result = NativeType.Parse(s);
return new NFloat(result);
}
/// <summary>Converts the string representation of a number in a specified style to its floating-point number equivalent.</summary>
/// <param name="s">A string that contains the number to convert.</param>
/// <param name="style">A bitwise combination of enumeration values that indicate the style elements that can be present in <paramref name="s" />.</param>
/// <returns>A floating-point number that is equivalent to the numeric value or symbol specified in <paramref name="s" />.</returns>
/// <exception cref="ArgumentException">
/// <para><paramref name="style" /> is not a <see cref="NumberStyles" /> value.</para>
/// <para>-or-</para>
/// <para><paramref name="style" /> includes the <see cref="NumberStyles.AllowHexSpecifier" /> or <see cref="NumberStyles.AllowBinarySpecifier" /> value.</para>
/// </exception>
/// <exception cref="ArgumentNullException"><paramref name="s" /> is <c>null</c>.</exception>
/// <exception cref="FormatException"><paramref name="s" /> does not represent a number in a valid format.</exception>
public static NFloat Parse(string s, NumberStyles style)
{
var result = NativeType.Parse(s, style);
return new NFloat(result);
}
/// <summary>Converts the string representation of a number in a specified culture-specific format to its floating-point number equivalent.</summary>
/// <param name="s">A string that contains the number to convert.</param>
/// <param name="provider">An object that supplies culture-specific formatting information about <paramref name="s" />.</param>
/// <returns>A floating-point number that is equivalent to the numeric value or symbol specified in <paramref name="s" />.</returns>
/// <exception cref="ArgumentNullException"><paramref name="s" /> is <c>null</c>.</exception>
/// <exception cref="FormatException"><paramref name="s" /> does not represent a number in a valid format.</exception>
public static NFloat Parse(string s, IFormatProvider? provider)
{
var result = NativeType.Parse(s, provider);
return new NFloat(result);
}
/// <summary>Converts the string representation of a number in a specified style and culture-specific format to its floating-point number equivalent.</summary>
/// <param name="s">A string that contains the number to convert.</param>
/// <param name="style">A bitwise combination of enumeration values that indicate the style elements that can be present in <paramref name="s" />.</param>
/// <param name="provider">An object that supplies culture-specific formatting information about <paramref name="s" />.</param>
/// <returns>A floating-point number that is equivalent to the numeric value or symbol specified in <paramref name="s" />.</returns>
/// <exception cref="ArgumentException">
/// <para><paramref name="style" /> is not a <see cref="NumberStyles" /> value.</para>
/// <para>-or-</para>
/// <para><paramref name="style" /> includes the <see cref="NumberStyles.AllowHexSpecifier" /> or <see cref="NumberStyles.AllowBinarySpecifier" /> value.</para>
/// </exception>
/// <exception cref="ArgumentNullException"><paramref name="s" /> is <c>null</c>.</exception>
/// <exception cref="FormatException"><paramref name="s" /> does not represent a number in a valid format.</exception>
public static NFloat Parse(string s, NumberStyles style, IFormatProvider? provider)
{
var result = NativeType.Parse(s, style, provider);
return new NFloat(result);
}
/// <summary>Converts a character span that contains the string representation of a number in a specified style and culture-specific format to its floating-point number equivalent.</summary>
/// <param name="s">A character span that contains the number to convert.</param>
/// <param name="style">A bitwise combination of enumeration values that indicate the style elements that can be present in <paramref name="s" />.</param>
/// <param name="provider">An object that supplies culture-specific formatting information about <paramref name="s" />.</param>
/// <returns>A floating-point number that is equivalent to the numeric value or symbol specified in <paramref name="s" />.</returns>
/// <exception cref="ArgumentException">
/// <para><paramref name="style" /> is not a <see cref="NumberStyles" /> value.</para>
/// <para>-or-</para>
/// <para><paramref name="style" /> includes the <see cref="NumberStyles.AllowHexSpecifier" /> or <see cref="NumberStyles.AllowBinarySpecifier" /> value.</para>
/// </exception>
/// <exception cref="FormatException"><paramref name="s" /> does not represent a number in a valid format.</exception>
public static NFloat Parse(ReadOnlySpan<char> s, NumberStyles style = DefaultNumberStyles, IFormatProvider? provider = null)
{
var result = NativeType.Parse(s, style, provider);
return new NFloat(result);
}
/// <summary>Tries to convert the string representation of a number to its floating-point number equivalent.</summary>
/// <param name="s">A read-only character span that contains the number to convert.</param>
/// <param name="result">When this method returns, contains a floating-point number equivalent of the numeric value or symbol contained in <paramref name="s" /> if the conversion succeeded or zero if the conversion failed. The conversion fails if the <paramref name="s" /> is <c>null</c>, <see cref="string.Empty" />, or is not in a valid format. This parameter is passed uninitialized; any value originally supplied in result will be overwritten.</param>
/// <returns><c>true</c> if <paramref name="s" /> was converted successfully; otherwise, false.</returns>
public static bool TryParse([NotNullWhen(true)] string? s, out NFloat result)
{
Unsafe.SkipInit(out result);
return NativeType.TryParse(s, out Unsafe.As<NFloat, NativeType>(ref result));
}
/// <summary>Tries to convert a character span containing the string representation of a number to its floating-point number equivalent.</summary>
/// <param name="s">A read-only character span that contains the number to convert.</param>
/// <param name="result">When this method returns, contains a floating-point number equivalent of the numeric value or symbol contained in <paramref name="s" /> if the conversion succeeded or zero if the conversion failed. The conversion fails if the <paramref name="s" /> is <see cref="ReadOnlySpan{T}.Empty" /> or is not in a valid format. This parameter is passed uninitialized; any value originally supplied in result will be overwritten.</param>
/// <returns><c>true</c> if <paramref name="s" /> was converted successfully; otherwise, false.</returns>
public static bool TryParse(ReadOnlySpan<char> s, out NFloat result)
{
Unsafe.SkipInit(out result);
return NativeType.TryParse(s, out Unsafe.As<NFloat, NativeType>(ref result));
}
/// <summary>Tries to convert a UTF-8 character span containing the string representation of a number to its floating-point number equivalent.</summary>
/// <param name="utf8Text">A read-only UTF-8 character span that contains the number to convert.</param>
/// <param name="result">When this method returns, contains a floating-point number equivalent of the numeric value or symbol contained in <paramref name="utf8Text" /> if the conversion succeeded or zero if the conversion failed. The conversion fails if the <paramref name="utf8Text" /> is <see cref="ReadOnlySpan{T}.Empty" /> or is not in a valid format. This parameter is passed uninitialized; any value originally supplied in result will be overwritten.</param>
/// <returns><c>true</c> if <paramref name="utf8Text" /> was converted successfully; otherwise, false.</returns>
public static bool TryParse(ReadOnlySpan<byte> utf8Text, out NFloat result)
{
Unsafe.SkipInit(out result);
return NativeType.TryParse(utf8Text, out Unsafe.As<NFloat, NativeType>(ref result));
}
/// <summary>Tries to convert the string representation of a number in a specified style and culture-specific format to its floating-point number equivalent.</summary>
/// <param name="s">A read-only character span that contains the number to convert.</param>
/// <param name="style">A bitwise combination of enumeration values that indicate the style elements that can be present in <paramref name="s" />.</param>
/// <param name="provider">An object that supplies culture-specific formatting information about <paramref name="s" />.</param>
/// <param name="result">When this method returns, contains a floating-point number equivalent of the numeric value or symbol contained in <paramref name="s" /> if the conversion succeeded or zero if the conversion failed. The conversion fails if the <paramref name="s" /> is <c>null</c>, <see cref="string.Empty" />, or is not in a format compliant with <paramref name="style" />, or if <paramref name="style" /> is not a valid combination of <see cref="NumberStyles" /> enumeration constants. This parameter is passed uninitialized; any value originally supplied in result will be overwritten.</param>
/// <returns><c>true</c> if <paramref name="s" /> was converted successfully; otherwise, false.</returns>
/// <exception cref="ArgumentException">
/// <para><paramref name="style" /> is not a <see cref="NumberStyles" /> value.</para>
/// <para>-or-</para>
/// <para><paramref name="style" /> includes the <see cref="NumberStyles.AllowHexSpecifier" /> or <see cref="NumberStyles.AllowBinarySpecifier" /> value.</para>
/// </exception>
public static bool TryParse([NotNullWhen(true)] string? s, NumberStyles style, IFormatProvider? provider, out NFloat result)
{
Unsafe.SkipInit(out result);
return NativeType.TryParse(s, style, provider, out Unsafe.As<NFloat, NativeType>(ref result));
}
/// <summary>Tries to convert a character span containing the string representation of a number in a specified style and culture-specific format to its floating-point number equivalent.</summary>
/// <param name="s">A read-only character span that contains the number to convert.</param>
/// <param name="style">A bitwise combination of enumeration values that indicate the style elements that can be present in <paramref name="s" />.</param>
/// <param name="provider">An object that supplies culture-specific formatting information about <paramref name="s" />.</param>
/// <param name="result">When this method returns, contains a floating-point number equivalent of the numeric value or symbol contained in <paramref name="s" /> if the conversion succeeded or zero if the conversion failed. The conversion fails if the <paramref name="s" /> is <see cref="string.Empty" /> or is not in a format compliant with <paramref name="style" />, or if <paramref name="style" /> is not a valid combination of <see cref="NumberStyles" /> enumeration constants. This parameter is passed uninitialized; any value originally supplied in result will be overwritten.</param>
/// <returns><c>true</c> if <paramref name="s" /> was converted successfully; otherwise, false.</returns>
/// <exception cref="ArgumentException">
/// <para><paramref name="style" /> is not a <see cref="NumberStyles" /> value.</para>
/// <para>-or-</para>
/// <para><paramref name="style" /> includes the <see cref="NumberStyles.AllowHexSpecifier" /> or <see cref="NumberStyles.AllowBinarySpecifier" /> value.</para>
/// </exception>
public static bool TryParse(ReadOnlySpan<char> s, NumberStyles style, IFormatProvider? provider, out NFloat result)
{
Unsafe.SkipInit(out result);
return NativeType.TryParse(s, style, provider, out Unsafe.As<NFloat, NativeType>(ref result));
}
/// <summary>Compares this instance to a specified object and returns an integer that indicates whether the value of this instance is less than, equal to, or greater than the value of the specified object.</summary>
/// <param name="obj">An object to compare, or <c>null</c>.</param>
/// <returns>
/// <para>A signed number indicating the relative values of this instance and <paramref name="obj" />.</para>
/// <list type="table">
/// <listheader>
/// <term>Return Value</term>
/// <description>Description</description>
/// </listheader>
/// <item>
/// <term>Less than zero</term>
/// <description>This instance is less than <paramref name="obj" />, or this instance is not a number and <paramref name="obj" /> is a number.</description>
/// </item>
/// <item>
/// <term>Zero</term>
/// <description>This instance is equal to <paramref name="obj" />, or both this instance and <paramref name="obj" /> are not a number.</description>
/// </item>
/// <item>
/// <term>Greater than zero</term>
/// <description>This instance is greater than <paramref name="obj" />, or this instance is a number and <paramref name="obj" /> is not a number or <paramref name="obj" /> is <c>null</c>.</description>
/// </item>
/// </list>
/// </returns>
/// <exception cref="ArgumentException"><paramref name="obj" /> is not a <see cref="NFloat" />.</exception>
public int CompareTo(object? obj)
{
if (obj is NFloat other)
{
if (_value < other._value) return -1;
if (_value > other._value) return 1;
if (_value == other._value) return 0;
// At least one of the values is NaN.
if (NativeType.IsNaN(_value))
{
return NativeType.IsNaN(other._value) ? 0 : -1;
}
else
{
return 1;
}
}
else if (obj is null)
{
return 1;
}
throw new ArgumentException(SR.Arg_MustBeNFloat);
}
/// <summary>Compares this instance to a specified floating-point number and returns an integer that indicates whether the value of this instance is less than, equal to, or greater than the value of the specified floating-point number.</summary>
/// <param name="other">A floating-point number to compare.</param>
/// <returns>
/// <para>A signed number indicating the relative values of this instance and <paramref name="other" />.</para>
/// <list type="table">
/// <listheader>
/// <term>Return Value</term>
/// <description>Description</description>
/// </listheader>
/// <item>
/// <term>Less than zero</term>
/// <description>This instance is less than <paramref name="other" />, or this instance is not a number and <paramref name="other" /> is a number.</description>
/// </item>
/// <item>
/// <term>Zero</term>
/// <description>This instance is equal to <paramref name="other" />, or both this instance and <paramref name="other" /> are not a number.</description>
/// </item>
/// <item>
/// <term>Greater than zero</term>
/// <description>This instance is greater than <paramref name="other" />, or this instance is a number and <paramref name="other" /> is not a number.</description>
/// </item>
/// </list>
/// </returns>
public int CompareTo(NFloat other) => _value.CompareTo(other._value);
/// <summary>Returns a value indicating whether this instance is equal to a specified object.</summary>
/// <param name="obj">An object to compare with this instance.</param>
/// <returns><c>true</c> if <paramref name="obj"/> is an instance of <see cref="NFloat"/> and equals the value of this instance; otherwise, <c>false</c>.</returns>
public override bool Equals([NotNullWhen(true)] object? obj) => (obj is NFloat other) && Equals(other);
/// <summary>Returns a value indicating whether this instance is equal to a specified <see cref="NFloat" /> value.</summary>
/// <param name="other">An <see cref="NFloat"/> value to compare to this instance.</param>
/// <returns><c>true</c> if <paramref name="other"/> has the same value as this instance; otherwise, <c>false</c>.</returns>
public bool Equals(NFloat other) => _value.Equals(other._value);
/// <summary>Returns the hash code for this instance.</summary>
/// <returns>A 32-bit signed integer hash code.</returns>
public override int GetHashCode() => _value.GetHashCode();
/// <summary>Converts the numeric value of this instance to its equivalent string representation.</summary>
/// <returns>The string representation of the value of this instance.</returns>
public override string ToString() => _value.ToString();
/// <summary>Converts the numeric value of this instance to its equivalent string representation using the specified format.</summary>
/// <param name="format">A numeric format string.</param>
/// <returns>The string representation of the value of this instance as specified by <paramref name="format" />.</returns>
/// <exception cref="FormatException"><paramref name="format" /> is invalid.</exception>
public string ToString([StringSyntax(StringSyntaxAttribute.NumericFormat)] string? format) => _value.ToString(format);
/// <summary>Converts the numeric value of this instance to its equivalent string representation using the specified culture-specific format information.</summary>
/// <param name="provider">An object that supplies culture-specific formatting information.</param>
/// <returns>The string representation of the value of this instance as specified by <paramref name="provider" />.</returns>
public string ToString(IFormatProvider? provider)=> _value.ToString(provider);
/// <summary>Converts the numeric value of this instance to its equivalent string representation using the specified format and culture-specific format information.</summary>
/// <param name="format">A numeric format string.</param>
/// <param name="provider">An object that supplies culture-specific formatting information.</param>
/// <returns>The string representation of the value of this instance as specified by <paramref name="format" /> and <paramref name="provider" />.</returns>
/// <exception cref="FormatException"><paramref name="format" /> is invalid.</exception>
public string ToString([StringSyntax(StringSyntaxAttribute.NumericFormat)] string? format, IFormatProvider? provider) => _value.ToString(format, provider);
/// <summary>Tries to format the value of the current instance into the provided span of characters.</summary>
/// <param name="destination">The span in which to write this instance's value formatted as a span of characters.</param>
/// <param name="charsWritten">When this method returns, contains the number of characters that were written in <paramref name="destination" />.</param>
/// <param name="format">A span containing the characters that represent a standard or custom format string that defines the acceptable format for <paramref name="destination" />.</param>
/// <param name="provider">An optional object that supplies culture-specific formatting information for <paramref name="destination" />.</param>
/// <returns><c>true</c> if the formatting was successful; otherwise, <c>false</c>.</returns>
public bool TryFormat(Span<char> destination, out int charsWritten, [StringSyntax(StringSyntaxAttribute.NumericFormat)] ReadOnlySpan<char> format = default, IFormatProvider? provider = null) => _value.TryFormat(destination, out charsWritten, format, provider);
/// <inheritdoc cref="IUtf8SpanFormattable.TryFormat" />
public bool TryFormat(Span<byte> utf8Destination, out int bytesWritten, [StringSyntax(StringSyntaxAttribute.NumericFormat)] ReadOnlySpan<char> format = default, IFormatProvider? provider = null) => _value.TryFormat(utf8Destination, out bytesWritten, format, provider);
//
// IAdditiveIdentity
//
/// <inheritdoc cref="IAdditiveIdentity{TSelf, TResult}.AdditiveIdentity" />
static NFloat IAdditiveIdentity<NFloat, NFloat>.AdditiveIdentity => new NFloat(NativeType.AdditiveIdentity);
//
// IBinaryNumber
//
/// <inheritdoc cref="IBinaryNumber{TSelf}.AllBitsSet" />
static NFloat IBinaryNumber<NFloat>.AllBitsSet
{
#if TARGET_64BIT
[NonVersionable]
get => (NFloat)BitConverter.UInt64BitsToDouble(0xFFFF_FFFF_FFFF_FFFF);
#else
[NonVersionable]
get => BitConverter.UInt32BitsToSingle(0xFFFF_FFFF);
#endif
}
/// <inheritdoc cref="IBinaryNumber{TSelf}.IsPow2(TSelf)" />
public static bool IsPow2(NFloat value) => NativeType.IsPow2(value._value);
/// <inheritdoc cref="IBinaryNumber{TSelf}.Log2(TSelf)" />
public static NFloat Log2(NFloat value) => new NFloat(NativeType.Log2(value._value));
//
// IBitwiseOperators
//
/// <inheritdoc cref="IBitwiseOperators{TSelf, TOther, TResult}.op_BitwiseAnd(TSelf, TOther)" />
static NFloat IBitwiseOperators<NFloat, NFloat, NFloat>.operator &(NFloat left, NFloat right)
{
#if TARGET_32BIT
uint bits = BitConverter.SingleToUInt32Bits(left._value) & BitConverter.SingleToUInt32Bits(right._value);
NativeType result = BitConverter.UInt32BitsToSingle(bits);
return new NFloat(result);
#else
ulong bits = BitConverter.DoubleToUInt64Bits(left._value) & BitConverter.DoubleToUInt64Bits(right._value);
NativeType result = BitConverter.UInt64BitsToDouble(bits);
return new NFloat(result);
#endif
}
/// <inheritdoc cref="IBitwiseOperators{TSelf, TOther, TResult}.op_BitwiseOr(TSelf, TOther)" />
static NFloat IBitwiseOperators<NFloat, NFloat, NFloat>.operator |(NFloat left, NFloat right)
{
#if TARGET_32BIT
uint bits = BitConverter.SingleToUInt32Bits(left._value) | BitConverter.SingleToUInt32Bits(right._value);
NativeType result = BitConverter.UInt32BitsToSingle(bits);
return new NFloat(result);
#else
ulong bits = BitConverter.DoubleToUInt64Bits(left._value) | BitConverter.DoubleToUInt64Bits(right._value);
NativeType result = BitConverter.UInt64BitsToDouble(bits);
return new NFloat(result);
#endif
}
/// <inheritdoc cref="IBitwiseOperators{TSelf, TOther, TResult}.op_ExclusiveOr(TSelf, TOther)" />
static NFloat IBitwiseOperators<NFloat, NFloat, NFloat>.operator ^(NFloat left, NFloat right)
{
#if TARGET_32BIT
uint bits = BitConverter.SingleToUInt32Bits(left._value) ^ BitConverter.SingleToUInt32Bits(right._value);
NativeType result = BitConverter.UInt32BitsToSingle(bits);
return new NFloat(result);
#else
ulong bits = BitConverter.DoubleToUInt64Bits(left._value) ^ BitConverter.DoubleToUInt64Bits(right._value);
NativeType result = BitConverter.UInt64BitsToDouble(bits);
return new NFloat(result);
#endif
}
/// <inheritdoc cref="IBitwiseOperators{TSelf, TOther, TResult}.op_OnesComplement(TSelf)" />
static NFloat IBitwiseOperators<NFloat, NFloat, NFloat>.operator ~(NFloat value)
{
#if TARGET_32BIT
uint bits = ~BitConverter.SingleToUInt32Bits(value._value);
NativeType result = BitConverter.UInt32BitsToSingle(bits);
return new NFloat(result);
#else
ulong bits = ~BitConverter.DoubleToUInt64Bits(value._value);
NativeType result = BitConverter.UInt64BitsToDouble(bits);
return new NFloat(result);
#endif
}
//
// IExponentialFunctions
//
/// <inheritdoc cref="IExponentialFunctions{TSelf}.Exp" />
public static NFloat Exp(NFloat x) => new NFloat(NativeType.Exp(x._value));
/// <inheritdoc cref="IExponentialFunctions{TSelf}.ExpM1(TSelf)" />
public static NFloat ExpM1(NFloat x) => new NFloat(NativeType.ExpM1(x._value));
/// <inheritdoc cref="IExponentialFunctions{TSelf}.Exp2(TSelf)" />
public static NFloat Exp2(NFloat x) => new NFloat(NativeType.Exp2(x._value));
/// <inheritdoc cref="IExponentialFunctions{TSelf}.Exp2M1(TSelf)" />
public static NFloat Exp2M1(NFloat x) => new NFloat(NativeType.Exp2M1(x._value));
/// <inheritdoc cref="IExponentialFunctions{TSelf}.Exp10(TSelf)" />
public static NFloat Exp10(NFloat x) => new NFloat(NativeType.Exp10(x._value));
/// <inheritdoc cref="IExponentialFunctions{TSelf}.Exp10M1(TSelf)" />
public static NFloat Exp10M1(NFloat x) => new NFloat(NativeType.Exp10M1(x._value));
//
// IFloatingPoint
//
/// <inheritdoc cref="IFloatingPoint{TSelf}.Ceiling(TSelf)" />
public static NFloat Ceiling(NFloat x) => new NFloat(NativeType.Ceiling(x._value));
/// <inheritdoc cref="IFloatingPoint{TSelf}.Floor(TSelf)" />
public static NFloat Floor(NFloat x) => new NFloat(NativeType.Floor(x._value));
/// <inheritdoc cref="IFloatingPoint{TSelf}.Round(TSelf)" />
public static NFloat Round(NFloat x) => new NFloat(NativeType.Round(x._value));