Skip to contentSkip to conversation

xfstests: don't remove trailing zeros from integers

PATCH Superseded Eric Whitney 4 participants 5 messages Mar 1, 2013 – Mar 5, 2013

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 xfstests: don't remove trailing zeros from integers

_within_tolerance strips trailing zeros from the min and max range values it outputs. This leads to damage if the min or max value is an integer containing trailing zeros rather than a real number with a fractional part containing trailing zeros. Xfstest 289 can exhibit this problem when its input is out of range. Modify the code so it will only remove trailing zeros found after a decimal point, and remove decimal points not followed by digits.

---
 common.filter |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
common.filter +5 -2
index 9e4c90c..bfc800b 100644
@@ -106,8 +106,11 @@ EOF
 
   # fix up min, max precision for output
   # can vary for 5.3, 6.2
-  _min=`echo $_min | sed -e 's/0*$//'` # get rid of trailling zeroes
-  _max=`echo $_max | sed -e 's/0*$//'` # get rid of trailling zeroes
+
+  # remove any trailing zeroes from min, max if they have fractional parts
+  # and then remove any decimal points not followed by digits
+  _min=`echo $_min | sed -e '/\./s/0*$//' | sed -e 's/\.$//'`
+  _max=`echo $_max | sed -e '/\./s/0*$//' | sed -e 's/\.$//'`
 
   if [ $_in_range -eq 1 ] 
   then
Signature · 6 lines
1.7.10.4

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#1 lore raw
Quoted 18 lines · Eric Whitney

_within_tolerance strips trailing zeros from the min and max range values it outputs. This leads to damage if the min or max value is an integer containing trailing zeros rather than a real number with a fractional part containing trailing zeros. Xfstest 289 can exhibit this problem when its input is out of range. Modify the code so it will only remove trailing zeros found after a decimal point, and remove decimal points not followed by digits.

---
 common.filter |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
common.filter +0 -0
index 9e4c90c..bfc800b 100644

common.filter EOF · line 113

Quoted 10 lines
common.filter +5 -2
@@ -106,8 +106,11 @@ EOF
 
   # fix up min, max precision for output
   # can vary for 5.3, 6.2
-  _min=`echo $_min | sed -e 's/0*$//'` # get rid of trailling zeroes
-  _max=`echo $_max | sed -e 's/0*$//'` # get rid of trailling zeroes
+
+  # remove any trailing zeroes from min, max if they have fractional parts
+  # and then remove any decimal points not followed by digits
+  _min=`echo $_min | sed -e '/\./s/0*$//' | sed -e 's/\.$//'`
+  _max=`echo $_max | sed -e '/\./s/0*$//' | sed -e 's/\.$//'`

You can do this with a single sed invocation via multiple expressions:

$ echo 200.00 | sed -e '/\./s/0*$//' -e 's/\.$//'
200
$

Cheers,

Dave.

Signature · 7 lines
Dave Chinner
[email protected]

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#2 lore raw
Quoted 20 lines · Dave Chinner
Quoted 19 lines · Eric Whitney

_within_tolerance strips trailing zeros from the min and max range values it outputs. This leads to damage if the min or max value is an integer containing trailing zeros rather than a real number with a fractional part containing trailing zeros. Xfstest 289 can exhibit this problem when its input is out of range. Modify the code so it will only remove trailing zeros found after a decimal point, and remove decimal points not followed by digits.

---
  common.filter |    7 +++++--
  1 file changed, 5 insertions(+), 2 deletions(-)
common.filter +0 -0
index 9e4c90c..bfc800b 100644
@@ -106,8 +106,11 @@ EOF
 
Quoted 9 lines

common.filter EOF · line 113

Quoted 9 lines
common.filter +5 -2
    # fix up min, max precision for output
    # can vary for 5.3, 6.2
-  _min=`echo $_min | sed -e 's/0*$//'` # get rid of trailling zeroes
-  _max=`echo $_max | sed -e 's/0*$//'` # get rid of trailling zeroes
+
+  # remove any trailing zeroes from min, max if they have fractional parts
+  # and then remove any decimal points not followed by digits
+  _min=`echo $_min | sed -e '/\./s/0*$//' | sed -e 's/\.$//'`
+  _max=`echo $_max | sed -e '/\./s/0*$//' | sed -e 's/\.$//'`

I like Dave's suggestion to change it to the following, what do you think Eric?

+  _min=`echo $_min | sed -e '/\./s/0*$//' -e 's/\.$//'` # get rid of trailing zeros
+  _max=`echo $_max | sed -e '/\./s/0*$//' -e 's/\.$//'` # get rid of trailing zeros

Regards
--Rich

Quoted 4 lines

You can do this with a single sed invocation via multiple expressions:

Quoted 8 lines
$ echo 200.00 | sed -e '/\./s/0*$//' -e 's/\.$//'
200
$

Cheers,

Dave.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#3 lore raw
Quoted 33 lines · Rich Johnston
Quoted 20 lines · Dave Chinner
Quoted 19 lines · Eric Whitney

_within_tolerance strips trailing zeros from the min and max range values it outputs. This leads to damage if the min or max value is an integer containing trailing zeros rather than a real number with a fractional part containing trailing zeros. Xfstest 289 can exhibit this problem when its input is out of range. Modify the code so it will only remove trailing zeros found after a decimal point, and remove decimal points not followed by digits.

---
  common.filter |    7 +++++--
  1 file changed, 5 insertions(+), 2 deletions(-)
common.filter +0 -0
index 9e4c90c..bfc800b 100644
@@ -106,8 +106,11 @@ EOF
 
Quoted 9 lines

common.filter EOF · line 113

Quoted 9 lines
common.filter +5 -2
    # fix up min, max precision for output
    # can vary for 5.3, 6.2
-  _min=`echo $_min | sed -e 's/0*$//'` # get rid of trailling zeroes
-  _max=`echo $_max | sed -e 's/0*$//'` # get rid of trailling zeroes
+
+  # remove any trailing zeroes from min, max if they have fractional parts
+  # and then remove any decimal points not followed by digits
+  _min=`echo $_min | sed -e '/\./s/0*$//' | sed -e 's/\.$//'`
+  _max=`echo $_max | sed -e '/\./s/0*$//' | sed -e 's/\.$//'`

I like Dave's suggestion to change it to the following, what do you think Eric?

Review

Quoted 2 lines
(quoted diff) +2 -0
+  _min=`echo $_min | sed -e '/\./s/0*$//' -e 's/\.$//'` # get rid of trailing zeros
+  _max=`echo $_max | sed -e '/\./s/0*$//' -e 's/\.$//'` # get rid of trailing zeros

looks awesome. Don't much care. Better to just fix than to dither for too long, aiming for the best sed ever ;)

-Eric

Quoted 17 lines

Regards
--Rich

Quoted 12 lines

You can do this with a single sed invocation via multiple expressions:

$ echo 200.00 | sed -e '/\./s/0*$//' -e 's/\.$//'
200
$

Cheers,

Dave.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#4 lore raw
In reply to Rich Johnston

* Rich Johnston <[email protected]>:

Quoted 21 lines · Dave Chinner
Quoted 20 lines · Eric Whitney
Quoted 19 lines

_within_tolerance strips trailing zeros from the min and max range values it outputs. This leads to damage if the min or max value is an integer containing trailing zeros rather than a real number with a fractional part containing trailing zeros. Xfstest 289 can exhibit this problem when its input is out of range. Modify the code so it will only remove trailing zeros found after a decimal point, and remove decimal points not followed by digits.

---
 common.filter |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
common.filter +0 -0
index 9e4c90c..bfc800b 100644
@@ -106,8 +106,11 @@ EOF
 
Quoted 12 lines
Quoted 9 lines

common.filter EOF · line 113

Quoted 9 lines
common.filter +5 -2
   # fix up min, max precision for output
   # can vary for 5.3, 6.2
-  _min=`echo $_min | sed -e 's/0*$//'` # get rid of trailling zeroes
-  _max=`echo $_max | sed -e 's/0*$//'` # get rid of trailling zeroes
+
+  # remove any trailing zeroes from min, max if they have fractional parts
+  # and then remove any decimal points not followed by digits
+  _min=`echo $_min | sed -e '/\./s/0*$//' | sed -e 's/\.$//'`
+  _max=`echo $_max | sed -e '/\./s/0*$//' | sed -e 's/\.$//'`

I like Dave's suggestion to change it to the following, what do you think Eric?

I just posted a V3 containing Dave's simplification. I'd hoped there would be something like that, and much appreciate the suggestion.

Thanks,
Eric

Quoted 23 lines

+ _min=echo $_min | sed -e '/\./s/0*$//' -e 's/\.$//' # get rid of trailing zeros
+ _max=echo $_max | sed -e '/\./s/0*$//' -e 's/\.$//' # get rid of trailing zeros

Regards
--Rich

Quoted 12 lines

You can do this with a single sed invocation via multiple expressions:

$ echo 200.00 | sed -e '/\./s/0*$//' -e 's/\.$//'
200
$

Cheers,

Dave.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs