| | | 1 | | // ----------------------------------------------------------------------- |
| | | 2 | | // <copyright file="NumberExtensions.cs" company="Stéphane ANDRE"> |
| | | 3 | | // Copyright (c) Stéphane ANDRE. All rights reserved. |
| | | 4 | | // </copyright> |
| | | 5 | | // ----------------------------------------------------------------------- |
| | | 6 | | |
| | | 7 | | using System.Runtime.CompilerServices; |
| | | 8 | | |
| | | 9 | | #pragma warning disable IDE0130 // Namespace does not match folder structure |
| | | 10 | | namespace MyNet.Primitives; |
| | | 11 | | #pragma warning restore IDE0130 // Namespace does not match folder structure |
| | | 12 | | |
| | | 13 | | public static class NumberExtensions |
| | | 14 | | { |
| | | 15 | | public const int Ten = 10; |
| | | 16 | | public const int Hundred = 100; |
| | | 17 | | public const int Thousand = 1000; |
| | | 18 | | public const int Million = 1_000_000; |
| | | 19 | | public const int Billion = 1_000_000_000; |
| | | 20 | | |
| | | 21 | | extension(int value) |
| | | 22 | | { |
| | | 23 | | /// <summary> |
| | | 24 | | /// 5.Tens == 50. |
| | | 25 | | /// </summary> |
| | | 26 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 3 | 27 | | public int Tens() => value * Ten; |
| | | 28 | | |
| | | 29 | | /// <summary> |
| | | 30 | | /// 4.Hundreds() == 400. |
| | | 31 | | /// </summary> |
| | | 32 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 3 | 33 | | public int Hundreds() => value * Hundred; |
| | | 34 | | |
| | | 35 | | /// <summary> |
| | | 36 | | /// 3.Thousands() == 3000. |
| | | 37 | | /// </summary> |
| | | 38 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 3 | 39 | | public int Thousands() => value * Thousand; |
| | | 40 | | |
| | | 41 | | /// <summary> |
| | | 42 | | /// 2.Millions() == 2000000. |
| | | 43 | | /// </summary> |
| | | 44 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 3 | 45 | | public int Millions() => value * Million; |
| | | 46 | | |
| | | 47 | | /// <summary> |
| | | 48 | | /// 1.Billions() == 1000000000 (short scale). |
| | | 49 | | /// </summary> |
| | | 50 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 3 | 51 | | public int Billions() => value * Billion; |
| | | 52 | | } |
| | | 53 | | |
| | | 54 | | extension(long value) |
| | | 55 | | { |
| | | 56 | | /// <summary> |
| | | 57 | | /// 5.Tens == 50. |
| | | 58 | | /// </summary> |
| | | 59 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 3 | 60 | | public long Tens() => value * Ten; |
| | | 61 | | |
| | | 62 | | /// <summary> |
| | | 63 | | /// 4.Hundreds() == 400. |
| | | 64 | | /// </summary> |
| | | 65 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 3 | 66 | | public long Hundreds() => value * Hundred; |
| | | 67 | | |
| | | 68 | | /// <summary> |
| | | 69 | | /// 3.Thousands() == 3000. |
| | | 70 | | /// </summary> |
| | | 71 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 3 | 72 | | public long Thousands() => value * Thousand; |
| | | 73 | | |
| | | 74 | | /// <summary> |
| | | 75 | | /// 2.Millions() == 2000000. |
| | | 76 | | /// </summary> |
| | | 77 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 3 | 78 | | public long Millions() => value * Million; |
| | | 79 | | |
| | | 80 | | /// <summary> |
| | | 81 | | /// 1.Billions() == 1000000000 (short scale). |
| | | 82 | | /// </summary> |
| | | 83 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 3 | 84 | | public long Billions() => value * Billion; |
| | | 85 | | } |
| | | 86 | | |
| | | 87 | | extension(decimal value) |
| | | 88 | | { |
| | | 89 | | /// <summary> |
| | | 90 | | /// 5.Tens == 50. |
| | | 91 | | /// </summary> |
| | | 92 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 0 | 93 | | public decimal Tens() => value * Ten; |
| | | 94 | | |
| | | 95 | | /// <summary> |
| | | 96 | | /// 4.Hundreds() == 400. |
| | | 97 | | /// </summary> |
| | | 98 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 0 | 99 | | public decimal Hundreds() => value * Hundred; |
| | | 100 | | |
| | | 101 | | /// <summary> |
| | | 102 | | /// 3.Thousands() == 3000. |
| | | 103 | | /// </summary> |
| | | 104 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 0 | 105 | | public decimal Thousands() => value * Thousand; |
| | | 106 | | |
| | | 107 | | /// <summary> |
| | | 108 | | /// 2.Millions() == 2000000. |
| | | 109 | | /// </summary> |
| | | 110 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 0 | 111 | | public decimal Millions() => value * Million; |
| | | 112 | | |
| | | 113 | | /// <summary> |
| | | 114 | | /// 1.Billions() == 1000000000 (short scale). |
| | | 115 | | /// </summary> |
| | | 116 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 0 | 117 | | public decimal Billions() => value * Billion; |
| | | 118 | | } |
| | | 119 | | |
| | | 120 | | extension(double value) |
| | | 121 | | { |
| | | 122 | | /// <summary> |
| | | 123 | | /// 5.Tens == 50. |
| | | 124 | | /// </summary> |
| | | 125 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 3 | 126 | | public double Tens() => value * Ten; |
| | | 127 | | |
| | | 128 | | /// <summary> |
| | | 129 | | /// 4.Hundreds() == 400. |
| | | 130 | | /// </summary> |
| | | 131 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 3 | 132 | | public double Hundreds() => value * Hundred; |
| | | 133 | | |
| | | 134 | | /// <summary> |
| | | 135 | | /// 3.Thousands() == 3000. |
| | | 136 | | /// </summary> |
| | | 137 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 3 | 138 | | public double Thousands() => value * Thousand; |
| | | 139 | | |
| | | 140 | | /// <summary> |
| | | 141 | | /// 2.Millions() == 2000000. |
| | | 142 | | /// </summary> |
| | | 143 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 3 | 144 | | public double Millions() => value * Million; |
| | | 145 | | |
| | | 146 | | /// <summary> |
| | | 147 | | /// 1.Billions() == 1000000000 (short scale). |
| | | 148 | | /// </summary> |
| | | 149 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 3 | 150 | | public double Billions() => value * Billion; |
| | | 151 | | } |
| | | 152 | | } |
| | | 153 | | |