Mercurial > repos > IBBoard
annotate Lang/IBBMath.cs @ 79:a70d89de1435
Re #32: Add staged loading of translations
* Add "extends" attribute to schema so that translation files can define what they extend
* Add "get parent language" method to extractor
* Move loader to using XML translation sets
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Fri, 09 Apr 2010 19:48:51 +0000 |
parents | 298b2ff956bb |
children |
rev | line source |
---|---|
31
7a3749a2d8e6
Re #19 - Add "Round to half" method
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
1 // This file (IBBMath.cs) is a part of the IBBoard project and is copyright 2009 IBBoard |
7a3749a2d8e6
Re #19 - Add "Round to half" method
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
2 // |
7a3749a2d8e6
Re #19 - Add "Round to half" method
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
3 // The file and the library/program it is in are licensed under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING.LGPL for more information and the full license. |
7a3749a2d8e6
Re #19 - Add "Round to half" method
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
4 // |
7a3749a2d8e6
Re #19 - Add "Round to half" method
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
5 |
7a3749a2d8e6
Re #19 - Add "Round to half" method
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
6 using System; |
7a3749a2d8e6
Re #19 - Add "Round to half" method
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
7 |
7a3749a2d8e6
Re #19 - Add "Round to half" method
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
8 namespace IBBoard.Lang |
7a3749a2d8e6
Re #19 - Add "Round to half" method
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
9 { |
46
298b2ff956bb
* Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
39
diff
changeset
|
10 [Obsolete("Use IBBoard.CustomMeth.IBBMath instead")] |
34
d597feec5dd4
Closes #20 - Add rounding method with enum
IBBoard <dev@ibboard.co.uk>
parents:
33
diff
changeset
|
11 public enum RoundType |
d597feec5dd4
Closes #20 - Add rounding method with enum
IBBoard <dev@ibboard.co.uk>
parents:
33
diff
changeset
|
12 { |
d597feec5dd4
Closes #20 - Add rounding method with enum
IBBoard <dev@ibboard.co.uk>
parents:
33
diff
changeset
|
13 Up, |
d597feec5dd4
Closes #20 - Add rounding method with enum
IBBoard <dev@ibboard.co.uk>
parents:
33
diff
changeset
|
14 Down, |
d597feec5dd4
Closes #20 - Add rounding method with enum
IBBoard <dev@ibboard.co.uk>
parents:
33
diff
changeset
|
15 Banker, |
d597feec5dd4
Closes #20 - Add rounding method with enum
IBBoard <dev@ibboard.co.uk>
parents:
33
diff
changeset
|
16 UpToHalf, |
d597feec5dd4
Closes #20 - Add rounding method with enum
IBBoard <dev@ibboard.co.uk>
parents:
33
diff
changeset
|
17 DownToHalf, |
d597feec5dd4
Closes #20 - Add rounding method with enum
IBBoard <dev@ibboard.co.uk>
parents:
33
diff
changeset
|
18 BankerToHalf |
d597feec5dd4
Closes #20 - Add rounding method with enum
IBBoard <dev@ibboard.co.uk>
parents:
33
diff
changeset
|
19 } |
d597feec5dd4
Closes #20 - Add rounding method with enum
IBBoard <dev@ibboard.co.uk>
parents:
33
diff
changeset
|
20 |
d597feec5dd4
Closes #20 - Add rounding method with enum
IBBoard <dev@ibboard.co.uk>
parents:
33
diff
changeset
|
21 /// <summary> |
d597feec5dd4
Closes #20 - Add rounding method with enum
IBBoard <dev@ibboard.co.uk>
parents:
33
diff
changeset
|
22 /// IBBMath provides a number of custom Maths functions based on the core Math classes. |
d597feec5dd4
Closes #20 - Add rounding method with enum
IBBoard <dev@ibboard.co.uk>
parents:
33
diff
changeset
|
23 /// </summary> |
46
298b2ff956bb
* Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
39
diff
changeset
|
24 [Obsolete("Use IBBoard.CustomMeth.IBBMath instead")] |
31
7a3749a2d8e6
Re #19 - Add "Round to half" method
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
25 public class IBBMath |
7a3749a2d8e6
Re #19 - Add "Round to half" method
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
26 { |
7a3749a2d8e6
Re #19 - Add "Round to half" method
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
27 /// <summary> |
7a3749a2d8e6
Re #19 - Add "Round to half" method
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
28 /// Rounds a number to the closest half, with a bias towards whole numbers. This is equivalent to 'round-to-even' in that |
7a3749a2d8e6
Re #19 - Add "Round to half" method
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
29 /// 0.25 is rounded down to 0.0 and 0.75 is rounded up to 1.0 so that a bias isn't introduced by rounding. |
7a3749a2d8e6
Re #19 - Add "Round to half" method
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
30 /// </summary> |
7a3749a2d8e6
Re #19 - Add "Round to half" method
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
31 /// <param name="number"> |
7a3749a2d8e6
Re #19 - Add "Round to half" method
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
32 /// The <see cref="System.Double"/> to round to the nearest 0.5 |
7a3749a2d8e6
Re #19 - Add "Round to half" method
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
33 /// </param> |
7a3749a2d8e6
Re #19 - Add "Round to half" method
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
34 /// <returns> |
7a3749a2d8e6
Re #19 - Add "Round to half" method
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
35 /// <code>param</code> rounded to the nearest 0.5 |
7a3749a2d8e6
Re #19 - Add "Round to half" method
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
36 /// </returns> |
7a3749a2d8e6
Re #19 - Add "Round to half" method
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
37 public static double RoundToHalf(double number) |
7a3749a2d8e6
Re #19 - Add "Round to half" method
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
38 { |
46
298b2ff956bb
* Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
39
diff
changeset
|
39 return IBBoard.CustomMath.IBBMath.RoundToHalf(number); |
31
7a3749a2d8e6
Re #19 - Add "Round to half" method
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
40 } |
33
8971a1c48dbf
Re #18 - Add rounding to half methods
IBBoard <dev@ibboard.co.uk>
parents:
31
diff
changeset
|
41 |
8971a1c48dbf
Re #18 - Add rounding to half methods
IBBoard <dev@ibboard.co.uk>
parents:
31
diff
changeset
|
42 /// <summary> |
8971a1c48dbf
Re #18 - Add rounding to half methods
IBBoard <dev@ibboard.co.uk>
parents:
31
diff
changeset
|
43 /// Returns the largest whole or half number that is less than or equal to the specified number. |
8971a1c48dbf
Re #18 - Add rounding to half methods
IBBoard <dev@ibboard.co.uk>
parents:
31
diff
changeset
|
44 /// </summary> |
8971a1c48dbf
Re #18 - Add rounding to half methods
IBBoard <dev@ibboard.co.uk>
parents:
31
diff
changeset
|
45 /// <param name="number"> |
8971a1c48dbf
Re #18 - Add rounding to half methods
IBBoard <dev@ibboard.co.uk>
parents:
31
diff
changeset
|
46 /// The <see cref="System.Double"/> to round to the nearest 0.5 |
8971a1c48dbf
Re #18 - Add rounding to half methods
IBBoard <dev@ibboard.co.uk>
parents:
31
diff
changeset
|
47 /// </param> |
8971a1c48dbf
Re #18 - Add rounding to half methods
IBBoard <dev@ibboard.co.uk>
parents:
31
diff
changeset
|
48 /// <returns> |
8971a1c48dbf
Re #18 - Add rounding to half methods
IBBoard <dev@ibboard.co.uk>
parents:
31
diff
changeset
|
49 /// <code>param</code> rounded to the nearest 0.5 that is less than or equal to <code>param</code> |
8971a1c48dbf
Re #18 - Add rounding to half methods
IBBoard <dev@ibboard.co.uk>
parents:
31
diff
changeset
|
50 /// </returns> |
8971a1c48dbf
Re #18 - Add rounding to half methods
IBBoard <dev@ibboard.co.uk>
parents:
31
diff
changeset
|
51 public static double FloorToHalf(double number) |
8971a1c48dbf
Re #18 - Add rounding to half methods
IBBoard <dev@ibboard.co.uk>
parents:
31
diff
changeset
|
52 { |
46
298b2ff956bb
* Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
39
diff
changeset
|
53 return IBBoard.CustomMath.IBBMath.FloorToHalf(number); |
33
8971a1c48dbf
Re #18 - Add rounding to half methods
IBBoard <dev@ibboard.co.uk>
parents:
31
diff
changeset
|
54 } |
8971a1c48dbf
Re #18 - Add rounding to half methods
IBBoard <dev@ibboard.co.uk>
parents:
31
diff
changeset
|
55 |
8971a1c48dbf
Re #18 - Add rounding to half methods
IBBoard <dev@ibboard.co.uk>
parents:
31
diff
changeset
|
56 /// <summary> |
8971a1c48dbf
Re #18 - Add rounding to half methods
IBBoard <dev@ibboard.co.uk>
parents:
31
diff
changeset
|
57 /// Returns the smallest whole or half number that is greater than or equal to the specified number. |
8971a1c48dbf
Re #18 - Add rounding to half methods
IBBoard <dev@ibboard.co.uk>
parents:
31
diff
changeset
|
58 /// </summary> |
8971a1c48dbf
Re #18 - Add rounding to half methods
IBBoard <dev@ibboard.co.uk>
parents:
31
diff
changeset
|
59 /// <param name="number"> |
8971a1c48dbf
Re #18 - Add rounding to half methods
IBBoard <dev@ibboard.co.uk>
parents:
31
diff
changeset
|
60 /// The <see cref="System.Double"/> to round to the nearest 0.5 |
8971a1c48dbf
Re #18 - Add rounding to half methods
IBBoard <dev@ibboard.co.uk>
parents:
31
diff
changeset
|
61 /// </param> |
8971a1c48dbf
Re #18 - Add rounding to half methods
IBBoard <dev@ibboard.co.uk>
parents:
31
diff
changeset
|
62 /// <returns> |
8971a1c48dbf
Re #18 - Add rounding to half methods
IBBoard <dev@ibboard.co.uk>
parents:
31
diff
changeset
|
63 /// <code>param</code> rounded to the nearest 0.5 that is greater than or equal to <code>param</code> |
8971a1c48dbf
Re #18 - Add rounding to half methods
IBBoard <dev@ibboard.co.uk>
parents:
31
diff
changeset
|
64 /// </returns> |
8971a1c48dbf
Re #18 - Add rounding to half methods
IBBoard <dev@ibboard.co.uk>
parents:
31
diff
changeset
|
65 public static double CeilToHalf(double number) |
8971a1c48dbf
Re #18 - Add rounding to half methods
IBBoard <dev@ibboard.co.uk>
parents:
31
diff
changeset
|
66 { |
46
298b2ff956bb
* Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
39
diff
changeset
|
67 return IBBoard.CustomMath.IBBMath.CeilToHalf(number); |
33
8971a1c48dbf
Re #18 - Add rounding to half methods
IBBoard <dev@ibboard.co.uk>
parents:
31
diff
changeset
|
68 } |
34
d597feec5dd4
Closes #20 - Add rounding method with enum
IBBoard <dev@ibboard.co.uk>
parents:
33
diff
changeset
|
69 |
d597feec5dd4
Closes #20 - Add rounding method with enum
IBBoard <dev@ibboard.co.uk>
parents:
33
diff
changeset
|
70 /// <summary> |
d597feec5dd4
Closes #20 - Add rounding method with enum
IBBoard <dev@ibboard.co.uk>
parents:
33
diff
changeset
|
71 /// Returns the number rounded as defined by the <code>roundType</code> |
d597feec5dd4
Closes #20 - Add rounding method with enum
IBBoard <dev@ibboard.co.uk>
parents:
33
diff
changeset
|
72 /// </summary> |
d597feec5dd4
Closes #20 - Add rounding method with enum
IBBoard <dev@ibboard.co.uk>
parents:
33
diff
changeset
|
73 /// <param name="number"> |
d597feec5dd4
Closes #20 - Add rounding method with enum
IBBoard <dev@ibboard.co.uk>
parents:
33
diff
changeset
|
74 /// The <see cref="System.Double"/> to round |
d597feec5dd4
Closes #20 - Add rounding method with enum
IBBoard <dev@ibboard.co.uk>
parents:
33
diff
changeset
|
75 /// </param> |
d597feec5dd4
Closes #20 - Add rounding method with enum
IBBoard <dev@ibboard.co.uk>
parents:
33
diff
changeset
|
76 /// <param name="roundType"> |
d597feec5dd4
Closes #20 - Add rounding method with enum
IBBoard <dev@ibboard.co.uk>
parents:
33
diff
changeset
|
77 /// The way in which <code>number</code> should be rounded |
d597feec5dd4
Closes #20 - Add rounding method with enum
IBBoard <dev@ibboard.co.uk>
parents:
33
diff
changeset
|
78 /// </param> |
d597feec5dd4
Closes #20 - Add rounding method with enum
IBBoard <dev@ibboard.co.uk>
parents:
33
diff
changeset
|
79 /// <returns> |
d597feec5dd4
Closes #20 - Add rounding method with enum
IBBoard <dev@ibboard.co.uk>
parents:
33
diff
changeset
|
80 /// The rounded <see cref="System.Double"/> |
d597feec5dd4
Closes #20 - Add rounding method with enum
IBBoard <dev@ibboard.co.uk>
parents:
33
diff
changeset
|
81 /// </returns> |
d597feec5dd4
Closes #20 - Add rounding method with enum
IBBoard <dev@ibboard.co.uk>
parents:
33
diff
changeset
|
82 public static double Round(double number, RoundType roundType) |
d597feec5dd4
Closes #20 - Add rounding method with enum
IBBoard <dev@ibboard.co.uk>
parents:
33
diff
changeset
|
83 { |
46
298b2ff956bb
* Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
39
diff
changeset
|
84 IBBoard.CustomMath.RoundType newRoundType = (IBBoard.CustomMath.RoundType) Enum.Parse(typeof(IBBoard.CustomMath.RoundType), roundType.ToString()); |
298b2ff956bb
* Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
39
diff
changeset
|
85 return IBBoard.CustomMath.IBBMath.Round(number, newRoundType); |
34
d597feec5dd4
Closes #20 - Add rounding method with enum
IBBoard <dev@ibboard.co.uk>
parents:
33
diff
changeset
|
86 } |
39
ebc01964a918
* Add short method to round up or down based on a boolean - useful for compacting rounding up/down calls when they need to be done inline
IBBoard <dev@ibboard.co.uk>
parents:
34
diff
changeset
|
87 |
ebc01964a918
* Add short method to round up or down based on a boolean - useful for compacting rounding up/down calls when they need to be done inline
IBBoard <dev@ibboard.co.uk>
parents:
34
diff
changeset
|
88 /// <summary> |
ebc01964a918
* Add short method to round up or down based on a boolean - useful for compacting rounding up/down calls when they need to be done inline
IBBoard <dev@ibboard.co.uk>
parents:
34
diff
changeset
|
89 /// Returns the number rounded up or down to the closest whole number. |
ebc01964a918
* Add short method to round up or down based on a boolean - useful for compacting rounding up/down calls when they need to be done inline
IBBoard <dev@ibboard.co.uk>
parents:
34
diff
changeset
|
90 /// </summary> |
ebc01964a918
* Add short method to round up or down based on a boolean - useful for compacting rounding up/down calls when they need to be done inline
IBBoard <dev@ibboard.co.uk>
parents:
34
diff
changeset
|
91 /// <param name="number"> |
ebc01964a918
* Add short method to round up or down based on a boolean - useful for compacting rounding up/down calls when they need to be done inline
IBBoard <dev@ibboard.co.uk>
parents:
34
diff
changeset
|
92 /// The <see cref="System.Double"/> to round |
ebc01964a918
* Add short method to round up or down based on a boolean - useful for compacting rounding up/down calls when they need to be done inline
IBBoard <dev@ibboard.co.uk>
parents:
34
diff
changeset
|
93 /// </param> |
ebc01964a918
* Add short method to round up or down based on a boolean - useful for compacting rounding up/down calls when they need to be done inline
IBBoard <dev@ibboard.co.uk>
parents:
34
diff
changeset
|
94 /// <param name="roundUp"> |
ebc01964a918
* Add short method to round up or down based on a boolean - useful for compacting rounding up/down calls when they need to be done inline
IBBoard <dev@ibboard.co.uk>
parents:
34
diff
changeset
|
95 /// <code>true</code> to round up, else rounds down |
ebc01964a918
* Add short method to round up or down based on a boolean - useful for compacting rounding up/down calls when they need to be done inline
IBBoard <dev@ibboard.co.uk>
parents:
34
diff
changeset
|
96 /// </param> |
ebc01964a918
* Add short method to round up or down based on a boolean - useful for compacting rounding up/down calls when they need to be done inline
IBBoard <dev@ibboard.co.uk>
parents:
34
diff
changeset
|
97 /// <returns> |
ebc01964a918
* Add short method to round up or down based on a boolean - useful for compacting rounding up/down calls when they need to be done inline
IBBoard <dev@ibboard.co.uk>
parents:
34
diff
changeset
|
98 /// The rounded <see cref="System.Double"/> |
ebc01964a918
* Add short method to round up or down based on a boolean - useful for compacting rounding up/down calls when they need to be done inline
IBBoard <dev@ibboard.co.uk>
parents:
34
diff
changeset
|
99 /// </returns> |
ebc01964a918
* Add short method to round up or down based on a boolean - useful for compacting rounding up/down calls when they need to be done inline
IBBoard <dev@ibboard.co.uk>
parents:
34
diff
changeset
|
100 public static double Round(double number, bool roundUp) |
ebc01964a918
* Add short method to round up or down based on a boolean - useful for compacting rounding up/down calls when they need to be done inline
IBBoard <dev@ibboard.co.uk>
parents:
34
diff
changeset
|
101 { |
46
298b2ff956bb
* Move IBBMath to a more sensible package - we're not in Java, so "lang" isn't the catch-all package
IBBoard <dev@ibboard.co.uk>
parents:
39
diff
changeset
|
102 return IBBoard.CustomMath.IBBMath.Round(number, roundUp); |
39
ebc01964a918
* Add short method to round up or down based on a boolean - useful for compacting rounding up/down calls when they need to be done inline
IBBoard <dev@ibboard.co.uk>
parents:
34
diff
changeset
|
103 } |
31
7a3749a2d8e6
Re #19 - Add "Round to half" method
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
104 } |
7a3749a2d8e6
Re #19 - Add "Round to half" method
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
105 } |