[PATCH] issue1235: Prevent division by zeros leading to NaNs
Wald Commits
scm-commit at wald.intevation.org
Mon Jul 8 10:16:00 CEST 2013
# HG changeset patch
# User Felix Wolfsteller <felix.wolfsteller at intevation.de>
# Date 1373271925 -7200
# Node ID 1ca0688dddc78c2539aaf61bdd83bd393c54b598
# Parent c5945aca0c8d209847428f3cb57418965ca99eb7
issue1235: Prevent division by zeros leading to NaNs.
diff -r c5945aca0c8d -r 1ca0688dddc7 artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadCalculation.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadCalculation.java Fri Jul 05 12:16:46 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadCalculation.java Mon Jul 08 10:25:25 2013 +0200
@@ -187,12 +187,28 @@
}
}
SedimentLoadFraction fr = resLoad.getFraction(km);
- resLoad.setCoarse(km, fr.getCoarse()/cSum, fr.getCoarseRange());
- resLoad.setFineMiddle(km, fr.getFineMiddle()/fmSum, fr.getFineMiddleRange());
- resLoad.setSand(km, fr.getSand()/sSum, fr.getSandRange());
- resLoad.setSuspSand(km, fr.getSuspSand()/ssSum, fr.getSuspSandRange());
- resLoad.setSuspSandBed(km, fr.getSuspSandBed()/ssbSum, fr.getSuspSandBedRange());
- resLoad.setSuspSediment(km, fr.getSuspSediment()/sseSum, fr.getSuspSedimentRange());
+ // Prevent divisions by zero, the fraction defaults to 0d.
+ if (cSum != 0) {
+ resLoad.setCoarse(km, fr.getCoarse()/cSum, fr.getCoarseRange());
+ }
+ if (fmSum != 0) {
+ resLoad.setFineMiddle(km, fr.getFineMiddle()/fmSum,
+ fr.getFineMiddleRange());
+ }
+ if (sSum != 0) {
+ resLoad.setSand(km, fr.getSand()/sSum, fr.getSandRange());
+ }
+ if (ssSum != 0) {
+ resLoad.setSuspSand(km, fr.getSuspSand()/ssSum,
+ fr.getSuspSandRange());
+ }
+ if (ssbSum != 0) {
+ resLoad.setSuspSandBed(km, fr.getSuspSandBed()/ssbSum,
+ fr.getSuspSandBedRange());
+ }
+ if (sseSum != 0) {
+ resLoad.setSuspSediment(km, fr.getSuspSediment()/sseSum, fr.getSuspSedimentRange());
+ }
}
resLoad.setDescription("");
resLoad.setEpoch(true);
More information about the Dive4elements-commits
mailing list