Skip to content

Commit 0dc5bd6

Browse files
committed
NumberParser 1.0.8.5 & UnitParser 1.0.9.1.
1 parent d4e4d20 commit 0dc5bd6

File tree

6 files changed

+75
-53
lines changed

6 files changed

+75
-53
lines changed

all_binaries/NumberParser.jar

855 Bytes
Binary file not shown.
395 Bytes
Binary file not shown.

all_code/NumberParser/src_Internal/InternalNumberParser/ExistingOperations.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ public enum ExistingOperations
44
{
55
Multiplication, Division, Addition, Subtraction, Greater, GreaterOrEqual, Smaller,
66
SmallerOrEqual, Modulo, Abs, Acos, Asin, Atan, Atan2, BigMul, Ceiling, Cos, Cosh,
7-
DivRem, Exp, Floor, IEEERemainder, Log, Log10, Max, Min, Pow, Round, Sign, Sin, Sinh,
8-
Sqrt, Tan, Tanh, Truncate
7+
DivRem, Exp, Floor, IEEERemainder, Log, Log10, Max, Min, Round, Sign, Sin, Sinh,
8+
Tan, Tanh, Truncate
99
}

all_code/NumberParser/src_Internal/InternalNumberParser/Math2Internal/Math2Existing.java

Lines changed: 30 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,36 @@
1212
@SuppressWarnings("serial")
1313
public class Math2Existing
1414
{
15+
//The Pow/Sqrt methods are expected to only be used with values supported
16+
//by the in-built alternatives. As far as the calculations are performed with
17+
//PowDecimal/PowSqrt, which can deal with values of any size, it is required to
18+
//check whether an error should be thrown. PowSqrtPrecheckInput focuses on
19+
//analysing the input values.
20+
public static Number PowSqrtPrecheckInput(NumberD input)
21+
{
22+
boolean isOK = true;
23+
24+
NumberD input2 = new NumberD(input);
25+
if
26+
(
27+
!input2.getError().equals(ErrorTypesNumber.None)
28+
)
29+
{
30+
isOK = false;
31+
}
32+
else
33+
{
34+
input2 = OperationsManaged.PassBaseTenToValue(input2);
35+
if
36+
(
37+
input2.getBaseTenExponent() > 0
38+
)
39+
{ isOK = false; }
40+
}
41+
42+
return (isOK ? new Number(input2) : null);
43+
}
44+
1545
public static NumberD PerformOperationOneOperand(NumberD n, ExistingOperations operation)
1646
{
1747
NumberD n2 = AdaptInputsToMathMethod
@@ -385,32 +415,6 @@ else if (operation == ExistingOperations.Sinh)
385415
)
386416
);
387417
}
388-
else if (operation == ExistingOperations.Sqrt)
389-
{
390-
n.setValue
391-
(
392-
Math.sqrt
393-
(
394-
Conversions.ConvertTargetToDouble
395-
(
396-
n.getValue()
397-
)
398-
)
399-
);
400-
}
401-
else if (operation == ExistingOperations.Sqrt)
402-
{
403-
n.setValue
404-
(
405-
Math.sqrt
406-
(
407-
Conversions.ConvertTargetToDouble
408-
(
409-
n.getValue()
410-
)
411-
)
412-
);
413-
}
414418
else if (operation == ExistingOperations.Tan)
415419
{
416420
n.setValue
@@ -578,23 +582,6 @@ else if (operation == ExistingOperations.Log)
578582
)
579583
);
580584
}
581-
else if (operation == ExistingOperations.Pow)
582-
{
583-
n1.setValue
584-
(
585-
Math.pow
586-
(
587-
Conversions.ConvertTargetToDouble
588-
(
589-
n1.getValue()
590-
),
591-
Conversions.ConvertTargetToDouble
592-
(
593-
n2.getValue()
594-
)
595-
)
596-
);
597-
}
598585

599586
return
600587
(

all_code/NumberParser/src_Public/NumberParser/Math2.java

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -329,10 +329,28 @@ public static NumberD Min(NumberD n1, NumberD n2)
329329
**/
330330
public static NumberD Pow(NumberD n1, NumberD n2)
331331
{
332-
return Math2Existing.PerformOperationTwoOperands
333-
(
334-
n1, n2, ExistingOperations.Pow
335-
);
332+
Number n12 = Math2Existing.PowSqrtPrecheckInput(n1);
333+
Number n22 = Math2Existing.PowSqrtPrecheckInput(n2);
334+
335+
boolean isOK = (n12 != null && n22 != null);
336+
Number output = null;
337+
if (isOK)
338+
{
339+
output = Math2.PowDecimal(n12, n22.getValue());
340+
if
341+
(
342+
!output.getError().equals(ErrorTypesNumber.None) ||
343+
output.greaterThan(new Number(Double.MAX_VALUE)) ||
344+
output.lessThan(new Number(Double.MIN_VALUE))
345+
)
346+
{ isOK = false; }
347+
}
348+
349+
return
350+
(
351+
isOK ? new NumberD(output) :
352+
new NumberD(ErrorTypesNumber.NativeMethodError)
353+
);
336354
}
337355

338356
/**
@@ -440,10 +458,27 @@ public static NumberD Sinh(NumberD n)
440458
**/
441459
public static NumberD Sqrt(NumberD n)
442460
{
443-
return Math2Existing.PerformOperationOneOperand
444-
(
445-
n, ExistingOperations.Sqrt
446-
);
461+
Number n2 = Math2Existing.PowSqrtPrecheckInput(n);
462+
463+
boolean isOK = (n2 != null);
464+
Number output = null;
465+
if (isOK)
466+
{
467+
output = Math2.SqrtDecimal(n2);
468+
if
469+
(
470+
!output.getError().equals(ErrorTypesNumber.None) ||
471+
output.greaterThan(new Number(Double.MAX_VALUE)) ||
472+
output.lessThan(new Number(Double.MIN_VALUE))
473+
)
474+
{ isOK = false; }
475+
}
476+
477+
return
478+
(
479+
isOK ? new NumberD(output) :
480+
new NumberD(ErrorTypesNumber.NativeMethodError)
481+
);
447482
}
448483

449484
/**

all_comments/NumberParser.doc.zip

158 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)