Skip to content

Commit 828b087

Browse files
committed
NumberParser 1.0.8.5 & UnitParser 1.0.9.1.
1 parent 4f6255c commit 828b087

2 files changed

Lines changed: 282 additions & 0 deletions

File tree

all_code/NumberParser/README.md

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
# NumberParser (Java)
2+
3+
[Test program](https://github.com/varocarbas/FlexibleParser_Java/blob/master/all_code/Test/src/Parts/NumberParser.java)
4+
5+
[https://customsolvers.com/number_parser_java/](https://customsolvers.com/number_parser_java/) (ES: [https://customsolvers.com/number_parser_java_es/](https://customsolvers.com/number_parser_java_es/))
6+
7+
## Introduction
8+
9+
The ```NumberParser``` package provides a common framework to deal with all the Java numeric types. It relies on the following four classes (NumberX):
10+
- ```Number``` only supports the ```double``` type.
11+
- ```NumberD``` can support any numeric type via ```Object```.
12+
- ```NumberO``` can support different numeric types simultaneously.
13+
- ```NumberP``` can parse numbers from strings.
14+
15+
```Java
16+
//1.23 (double).
17+
Number number = new Number(1.23);
18+
19+
//123 (int).
20+
NumberD numberD = new NumberD(123);
21+
22+
//1.23 (double). Others: 1 (int) and '' (char).
23+
NumberO numberO = new NumberO
24+
(
25+
1.23, new ArrayList()
26+
{{
27+
add(NumericTypes.Integer);
28+
add(NumericTypes.Character);
29+
}}
30+
);
31+
32+
//1 (long).
33+
NumberP numberP = new NumberP
34+
(
35+
"1.23", new ParseConfig(NumericTypes.Long)
36+
);
37+
```
38+
39+
## Common Features
40+
41+
All the NumberX classes have various characteristics in common.
42+
- Defined according to ```getValue()``` (```double``` or ```Object```) and ```getBaseTenExponent()``` (```int```). All of them support ranges beyond [-1, 1] * 10^2147483647.
43+
- Static (```NumberD.Addition(numberD1, numberD2)```) and non-static (```numberD1.greaterThan(numberD2)```) support for the main arithmetic and comparison operations.
44+
- Errors managed internally and no exceptions thrown.
45+
- Numerous instantiating alternatives.
46+
47+
```Java
48+
//12.3*10^456 (double).
49+
Number number = new Number(12.3, 456);
50+
51+
//123 (int).
52+
NumberD numberD =
53+
(
54+
new NumberD(123).lessThan(new NumberD(new Number(456))) ?
55+
//123 (int)
56+
new NumberD(123.456, NumericTypes.Integer) :
57+
//123.456 (double)
58+
new NumberD(123.456)
59+
);
60+
61+
62+
//Error (ErrorTypesNumber.InvalidOperation) provoked when dividing by zero.
63+
NumberO numberO = NumberO.Division
64+
(
65+
new NumberO
66+
(
67+
123.0, OtherTypes.IntegerTypes
68+
)
69+
, new NumberO(0)
70+
);
71+
72+
//1.234000000000e+308*10^5373 (double).
73+
NumberP numberP = new NumberP("1234e5678");
74+
```
75+
76+
## Math2 Class
77+
78+
This class includes all the NumberParser mathematical functionalities.
79+
80+
### Custom Functionalities
81+
82+
- ```RoundExact```/```TruncateExact``` can deal with multiple rounding/truncating scenarios not supported by the native methods.
83+
- ```GetPolynomialFit```/```ApplyPolynomialFit``` allow to deal with second degree polynomial fits.
84+
- ```Factorial``` calculates the factorial of any integer number up to 100000.
85+
86+
```Java
87+
//123000 (double).
88+
Number number = Math2.RoundExact
89+
(
90+
new Number(123456.789), 3, RoundType.AlwaysToZero,
91+
RoundSeparator.BeforeDecimalSeparator
92+
);
93+
94+
//30 (double).
95+
NumberD numberD = Math2.ApplyPolynomialFit
96+
(
97+
Math2.GetPolynomialFit
98+
(
99+
new NumberD[]
100+
{
101+
new NumberD(1), new NumberD(2), new NumberD(4)
102+
},
103+
new NumberD[]
104+
{
105+
new NumberD(10), new NumberD(20), new NumberD(40)
106+
}
107+
)
108+
, new NumberD(3)
109+
);
110+
111+
//3628800 (int).
112+
NumberD numberD = Math2.Factorial(new NumberD(10));
113+
```
114+
115+
### Native Methods
116+
```Math2``` also includes ```NumberD```-adapted versions of a big number of ```Math``` and .NET ```System.Math``` methods.
117+
118+
It also includes ```PowDecimal```\```SqrtDecimal``` which allow to unrestrictedly use NumberX variables with ```Math.pow```\```Math.sqrt```. Note that this Java version doesn't rely on the original C# custom implementation (detailed explanations in [varocarbas.com Project 10](https://varocarbas.com/fractional_exponentiation/)) because of only making sense within the .NET conditions (i.e., high-precision ```decimal``` type not natively supported by the in-built methods).
119+
120+
```Java
121+
//1.582502898380e+14 (double).
122+
Number number = Math2.PowDecimal
123+
(
124+
new Number(123.45), 6.789101112131415161718
125+
);
126+
127+
//4.8158362157911885 (double).
128+
NumberD numberD = Math2.Log(new NumberD(123.45));
129+
```
130+
131+
## Further Code Samples
132+
The [test application](https://github.com/varocarbas/FlexibleParser/blob/master/all_code/Test/Parts/NumberParser.cs) includes a relevant number of descriptive code samples.
133+
134+
## Authorship & Copyright
135+
I, Alvaro Carballo Garcia (varocarbas), am the sole author of each single bit of this code.
136+
137+
Equivalently to what happens with all my other online contributions, this code can be considered public domain. For more information about my copyright/authorship attribution ideas, visit the corresponding pages of my sites:
138+
- https://customsolvers.com/copyright/<br/>
139+
ES: https://customsolvers.com/copyright_es/
140+
- https://varocarbas.com/copyright/<br/>
141+
ES: https://varocarbas.com/copyright_es/

all_readme/NumberParser_Java.md

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
# NumberParser (Java)
2+
3+
[Test program](https://github.com/varocarbas/FlexibleParser_Java/blob/master/all_code/Test/src/Parts/NumberParser.java)
4+
5+
[https://customsolvers.com/number_parser_java/](https://customsolvers.com/number_parser_java/) (ES: [https://customsolvers.com/number_parser_java_es/](https://customsolvers.com/number_parser_java_es/))
6+
7+
## Introduction
8+
9+
The ```NumberParser``` package provides a common framework to deal with all the Java numeric types. It relies on the following four classes (NumberX):
10+
- ```Number``` only supports the ```double``` type.
11+
- ```NumberD``` can support any numeric type via ```Object```.
12+
- ```NumberO``` can support different numeric types simultaneously.
13+
- ```NumberP``` can parse numbers from strings.
14+
15+
```Java
16+
//1.23 (double).
17+
Number number = new Number(1.23);
18+
19+
//123 (int).
20+
NumberD numberD = new NumberD(123);
21+
22+
//1.23 (double). Others: 1 (int) and '' (char).
23+
NumberO numberO = new NumberO
24+
(
25+
1.23, new ArrayList()
26+
{{
27+
add(NumericTypes.Integer);
28+
add(NumericTypes.Character);
29+
}}
30+
);
31+
32+
//1 (long).
33+
NumberP numberP = new NumberP
34+
(
35+
"1.23", new ParseConfig(NumericTypes.Long)
36+
);
37+
```
38+
39+
## Common Features
40+
41+
All the NumberX classes have various characteristics in common.
42+
- Defined according to ```getValue()``` (```double``` or ```Object```) and ```getBaseTenExponent()``` (```int```). All of them support ranges beyond [-1, 1] * 10^2147483647.
43+
- Static (```NumberD.Addition(numberD1, numberD2)```) and non-static (```numberD1.greaterThan(numberD2)```) support for the main arithmetic and comparison operations.
44+
- Errors managed internally and no exceptions thrown.
45+
- Numerous instantiating alternatives.
46+
47+
```Java
48+
//12.3*10^456 (double).
49+
Number number = new Number(12.3, 456);
50+
51+
//123 (int).
52+
NumberD numberD =
53+
(
54+
new NumberD(123).lessThan(new NumberD(new Number(456))) ?
55+
//123 (int)
56+
new NumberD(123.456, NumericTypes.Integer) :
57+
//123.456 (double)
58+
new NumberD(123.456)
59+
);
60+
61+
62+
//Error (ErrorTypesNumber.InvalidOperation) provoked when dividing by zero.
63+
NumberO numberO = NumberO.Division
64+
(
65+
new NumberO
66+
(
67+
123.0, OtherTypes.IntegerTypes
68+
)
69+
, new NumberO(0)
70+
);
71+
72+
//1.234000000000e+308*10^5373 (double).
73+
NumberP numberP = new NumberP("1234e5678");
74+
```
75+
76+
## Math2 Class
77+
78+
This class includes all the NumberParser mathematical functionalities.
79+
80+
### Custom Functionalities
81+
82+
- ```RoundExact```/```TruncateExact``` can deal with multiple rounding/truncating scenarios not supported by the native methods.
83+
- ```GetPolynomialFit```/```ApplyPolynomialFit``` allow to deal with second degree polynomial fits.
84+
- ```Factorial``` calculates the factorial of any integer number up to 100000.
85+
86+
```Java
87+
//123000 (double).
88+
Number number = Math2.RoundExact
89+
(
90+
new Number(123456.789), 3, RoundType.AlwaysToZero,
91+
RoundSeparator.BeforeDecimalSeparator
92+
);
93+
94+
//30 (double).
95+
NumberD numberD = Math2.ApplyPolynomialFit
96+
(
97+
Math2.GetPolynomialFit
98+
(
99+
new NumberD[]
100+
{
101+
new NumberD(1), new NumberD(2), new NumberD(4)
102+
},
103+
new NumberD[]
104+
{
105+
new NumberD(10), new NumberD(20), new NumberD(40)
106+
}
107+
)
108+
, new NumberD(3)
109+
);
110+
111+
//3628800 (int).
112+
NumberD numberD = Math2.Factorial(new NumberD(10));
113+
```
114+
115+
### Native Methods
116+
```Math2``` also includes ```NumberD```-adapted versions of a big number of ```Math``` and .NET ```System.Math``` methods.
117+
118+
It also includes ```PowDecimal```\```SqrtDecimal``` which allow to unrestrictedly use NumberX variables with ```Math.pow```\```Math.sqrt```. Note that this Java version doesn't rely on the original C# custom implementation (detailed explanations in [varocarbas.com Project 10](https://varocarbas.com/fractional_exponentiation/)) because of only making sense within the .NET conditions (i.e., high-precision ```decimal``` type not natively supported by the in-built methods).
119+
120+
```Java
121+
//1.582502898380e+14 (double).
122+
Number number = Math2.PowDecimal
123+
(
124+
new Number(123.45), 6.789101112131415161718
125+
);
126+
127+
//4.8158362157911885 (double).
128+
NumberD numberD = Math2.Log(new NumberD(123.45));
129+
```
130+
131+
## Further Code Samples
132+
The [test application](https://github.com/varocarbas/FlexibleParser/blob/master/all_code/Test/Parts/NumberParser.cs) includes a relevant number of descriptive code samples.
133+
134+
## Authorship & Copyright
135+
I, Alvaro Carballo Garcia (varocarbas), am the sole author of each single bit of this code.
136+
137+
Equivalently to what happens with all my other online contributions, this code can be considered public domain. For more information about my copyright/authorship attribution ideas, visit the corresponding pages of my sites:
138+
- https://customsolvers.com/copyright/<br/>
139+
ES: https://customsolvers.com/copyright_es/
140+
- https://varocarbas.com/copyright/<br/>
141+
ES: https://varocarbas.com/copyright_es/

0 commit comments

Comments
 (0)