--- loncom/homework/default_homework.lcpm 2001/12/04 14:49:37 1.42 +++ loncom/homework/default_homework.lcpm 2002/05/31 22:19:06 1.47 @@ -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.42 2001/12/04 14:49:37 albertel Exp $ +# $Id: default_homework.lcpm,v 1.47 2002/05/31 22:19:06 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -30,12 +30,14 @@ # # 05/25/2001 H. K. Ng # 05/31/2001 H. K. Ng +# 12/21/2001 Matthew # #init some globals $hidden::RANDOMINIT=0; $pi=atan2(1,1)*4; $rad2deg=180.0/$pi; $deg2rad=$pi/180.0; +$"=' '; sub caparesponse_check { #not properly used yet: calc @@ -99,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, @@ -208,7 +215,7 @@ sub web { if ( $external::target eq "tex" ) { return @_[1]; } else { - if ( $external::target eq "web") { + if ( $external::target eq "web" || $external::target eq "answer") { return @_[2]; } else { return @_[0]; @@ -236,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; @@ -437,6 +445,28 @@ 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 (!$exponent) { return $frac; } + 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);