version 1.97, 2005/03/31 14:43:13
|
version 1.100, 2005/06/17 20:24:56
|
Line 89 sub caparesponse_check {
|
Line 89 sub caparesponse_check {
|
} else { |
} else { |
$message .="no ws in :$response:\n"; |
$message .="no ws in :$response:\n"; |
} |
} |
if ($type eq 'cs' || $type eq 'ci' || $type eq 'mc') { |
&LONCAPA_INTERNAL_DEBUG(" type is $type "); |
|
if ($type eq 'cs' || $type eq 'ci') { |
#for string answers make surec all places spaces occur, there is |
#for string answers make surec all places spaces occur, there is |
#really only 1 space, in both the answer and the response |
#really only 1 space, in both the answer and the response |
$answer=~s/ +/ /g; |
$answer=~s/ +/ /g; |
$response=~s/ +/ /g; |
$response=~s/ +/ /g; |
|
} elsif ($type eq 'mc') { |
|
$answer=~s/[\s,]//g; |
|
$response=~s/[\s,]//g; |
} |
} |
if ($type eq 'float' && $unit=~/\$/) { |
if ($type eq 'float' && $unit=~/\$/) { |
if ($response!~/^\$/) { return "NO_UNIT: Missing \$ "; } |
if ($response!~/^\$/) { return "NO_UNIT: Missing \$ "; } |
Line 518 sub format {
|
Line 522 sub format {
|
#if ($options =~ /\$/) { $dollamode=1; } |
#if ($options =~ /\$/) { $dollamode=1; } |
#if ($options =~ /,/) { $commamode=1; } |
#if ($options =~ /,/) { $commamode=1; } |
if ($options =~ /\./) { $alwaysperiod=1; } |
if ($options =~ /\./) { $alwaysperiod=1; } |
|
my $result; |
if ($fmt=~/s$/i) { |
if ($fmt=~/s$/i) { |
$result=&format_significant_figures($value,$fmt); |
$result=&format_significant_figures($value,$fmt); |
} else { |
} else { |
$fmt=~s/e/E/g; |
$fmt=~s/e/E/g; |
my $result=sprintf('%.'.$fmt,$value); |
$result=sprintf('%.'.$fmt,$value); |
if ($alwaysperiod && $fmt eq '0f') { $result .='.'; } |
if ($alwaysperiod && $fmt eq '0f') { $result .='.'; } |
$result=~s/(E[+-]*)0/$1/; |
$result=~s/(E[+-]*)0/$1/; |
} |
} |
Line 680 sub format_significant_figures {
|
Line 685 sub format_significant_figures {
|
my $numSig = $xint*10**($x10-$sig+$power); |
my $numSig = $xint*10**($x10-$sig+$power); |
# insert trailing zero's if have decimal point |
# insert trailing zero's if have decimal point |
$numSig =~ s/^(\d+)\.(\d+)(\e?(.*)?)$/$1\.$2$zeros$3/; |
$numSig =~ s/^(\d+)\.(\d+)(\e?(.*)?)$/$1\.$2$zeros$3/; |
|
# put a decimal pt for number ending with 0 and length = # of sig fig |
|
$numSig.='.' if (length($numSig) == $sig && $numSig =~ /0$/); |
|
if (length($numSig) < $sig) { |
|
$numSig.='.'.substr($zeros,0,($sig-length($numSig))); |
|
} |
# return number with sign |
# return number with sign |
return $sign.$numSig; |
return $sign.$numSig; |
|
|