This repository has been archived by the owner on Apr 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes problem with type 'SLI' after using new Measurements app. Relea…
…se 6.14.4
- Loading branch information
Showing
9 changed files
with
2,825 additions
and
2,800 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System; | ||
|
||
namespace Extensions | ||
{ | ||
public static class Numerics | ||
{ | ||
public static double Rounding(double val, double rel_err) | ||
{ | ||
var abs_err = RoundError(val * (rel_err / 100)); | ||
|
||
int zeroCnt = (int)Math.Floor(Math.Log10(Math.Abs(abs_err))); | ||
|
||
if (zeroCnt < 0) | ||
return abs_err * Math.Pow(10, -zeroCnt) < 3 ? Math.Round(val, Math.Abs(zeroCnt) + 1) : Math.Round(val, Math.Abs(zeroCnt)); | ||
|
||
|
||
double scale = Math.Pow(10, Math.Floor(Math.Log10(Math.Abs(abs_err))) + 1); | ||
|
||
if ((abs_err / scale) < 0.3) // for value 248.34 and rounded error 130 should return 250 | ||
return (val / Math.Pow(10, zeroCnt - 1)) - Math.Floor((val / Math.Pow(10, zeroCnt - 1))) < 0.5 ? Math.Floor((val / Math.Pow(10, zeroCnt - 1))) * Math.Pow(10, zeroCnt - 1) : Math.Ceiling((val / Math.Pow(10, zeroCnt - 1))) * Math.Pow(10, zeroCnt - 1); | ||
|
||
|
||
return (val / Math.Pow(10, zeroCnt)) - Math.Floor((val / Math.Pow(10, zeroCnt))) < 0.5 ? Math.Floor((val / Math.Pow(10, zeroCnt))) * Math.Pow(10, zeroCnt) : Math.Ceiling((val / Math.Pow(10, zeroCnt))) * Math.Pow(10, zeroCnt); | ||
} | ||
|
||
private static double RoundError(double abs_err) | ||
{ | ||
int digits = 1; | ||
|
||
if (abs_err == 0) | ||
return 0; | ||
|
||
double scale = Math.Pow(10, Math.Floor(Math.Log10(Math.Abs(abs_err))) + 1); | ||
|
||
if ((abs_err / scale) < 0.3) | ||
digits = 2; | ||
|
||
return scale * Math.Round(abs_err / scale, digits); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.