--- loncom/homework/default_homework.lcpm 2001/12/21 21:37:26 1.44 +++ loncom/homework/default_homework.lcpm 2002/02/06 16:18:26 1.46 @@ -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.44 2001/12/21 21:37:26 matthew Exp $ +# $Id: default_homework.lcpm,v 1.46 2002/02/06 16:18:26 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -101,6 +101,11 @@ sub caparesponse_check { $sig_ubound =15; #SIG_UB_DEFAULT } else { ($sig_lbound,$sig_ubound) = split /,/,$sig; + if (!$sig_lbound) { + $sig_lbound = 0; #SIG_LB_DEFAULT + $sig_ubound =15; #SIG_UB_DEFAULT + } + if (!$sig_ubound) { $sig_ubound=$sig_lbound; } } my $result = &caparesponse_capa_check_answer($response,$answer,$type, $tol_type,$tol, @@ -238,6 +243,7 @@ sub random { srand($external::randomseed); $hidden::RANDOMINIT=1; } + if (!defined($step)) { $step=1; } my $num=1+int(($end-$start)/$step); my $result=$start + int(rand() * $num)*$step; return $result; @@ -439,6 +445,27 @@ sub format { return sprintf('%.'.$fmt,$value); } +sub prettyprint { + my ($value,$fmt)=@_; + my $result; + if ($fmt) { $value=sprintf('%.'.$fmt,$value); } + if ($value =~ /([0-9\.\-\+]+)E([0-9\-\+]+)/ ) { + my $frac=$1; + my $exponent=$2; + $exponent=~s/^\+0*//; + if ($external::target eq 'web') { + $result=$frac.'×10'.$exponent.''; + } elsif ($external::target eq 'tex') { + $result='\ensuremath{'.$frac.'\times 10^{'.$exponent.'}}'; + } else { + $result=$value; + } + } else { + $result=$value; + } + return $result; +} + sub map { my ($phrase,$dest,$source)=@_; my @seed = &random_seed_from_phrase($phrase);