[LON-CAPA-cvs] cvs: loncom /homework default_homework.lcpm
raeburn
raeburn at source.lon-capa.org
Wed Jun 25 06:48:39 EDT 2014
raeburn Wed Jun 25 10:48:39 2014 EDT
Modified files:
/loncom/homework default_homework.lcpm
Log:
- Bug 6613
Handle formatting correctly for numbers with absolute values of 10^15
or larger, and numbers smaller than 10^-4 in &format_significant_figures(),
in which perl automatically uses exponent form for initial value of $numSig.
Index: loncom/homework/default_homework.lcpm
diff -u loncom/homework/default_homework.lcpm:1.166 loncom/homework/default_homework.lcpm:1.167
--- loncom/homework/default_homework.lcpm:1.166 Tue Jun 24 18:02:47 2014
+++ loncom/homework/default_homework.lcpm Wed Jun 25 10:48:39 2014
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# used by lonxml::xmlparse() as input variable $safeinit to Apache::run::run()
#
-# $Id: default_homework.lcpm,v 1.166 2014/06/24 18:02:47 raeburn Exp $
+# $Id: default_homework.lcpm,v 1.167 2014/06/25 10:48:39 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -1059,7 +1059,11 @@
}
$numSig =~ s/^(\d+)\.(\d+)(\e?(.*)?)$/$1\.$2$zeros$3/;
} else {
- if ($numSig =~ /0$/) {
+ if ($numSig =~ /^(\d+)e([\+\-]\d+)$/i) {
+ my $pre_exp = $1;
+ my $exponent = $2;
+ $numSig = $pre_exp.'.'.$zeros.'E'.$exponent;
+ } elsif ($numSig =~ /0$/) {
# add decimal pt for number ending with 0 and length == # of sig figs
if (length($numSig) == $sig) {
$numSig.='.';
@@ -1067,12 +1071,15 @@
# exponential form for number ending with 0 and length > # of sig figs
my $fmtsig = $sig-1;
if ($fmtsig) {
- $numSig = sprintf('%.'.$fmtsig.'e',$numSig);
+ $numSig = sprintf('%.'.$fmtsig.'E',$numSig);
}
+ } elsif (length($numSig) < $sig) {
+ $numSig.='.'.substr($zeros,0,($sig-length($numSig)));
+ }
+ } else {
+ if (length($numSig) < $sig) {
+ $numSig.='.'.substr($zeros,0,($sig-length($numSig)));
}
- }
- if (length($numSig) < $sig) {
- $numSig.='.'.substr($zeros,0,($sig-length($numSig)));
}
}
# return number with sign
More information about the LON-CAPA-cvs
mailing list