[LON-CAPA-cvs] cvs: loncom /homework/caparesponse caparesponse.pm

raeburn raeburn at source.lon-capa.org
Sat Dec 5 00:01:18 EST 2020


raeburn		Sat Dec  5 05:01:18 2020 EDT

  Modified files:              
    /loncom/homework/caparesponse	caparesponse.pm 
  Log:
  - When generating values for bubbles for numericalresponse in exam mode,
    avoid a "use fewer digits" issue in online exams on 64bit servers when
    the correct answer is >= 1e+16, and when the correct bubble is A.
  
  
Index: loncom/homework/caparesponse/caparesponse.pm
diff -u loncom/homework/caparesponse/caparesponse.pm:1.261 loncom/homework/caparesponse/caparesponse.pm:1.262
--- loncom/homework/caparesponse/caparesponse.pm:1.261	Fri Dec  4 22:19:19 2020
+++ loncom/homework/caparesponse/caparesponse.pm	Sat Dec  5 05:01:18 2020
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # caparesponse definition
 #
-# $Id: caparesponse.pm,v 1.261 2020/12/04 22:19:19 raeburn Exp $
+# $Id: caparesponse.pm,v 1.262 2020/12/05 05:01:18 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1066,11 +1066,22 @@
     }
     for ($ind=0;$ind<$number_of_bubbles;$ind++) {
 	my $exponent = $power-$powers[$#powers-$ind];
+	$bubble_values[$ind] = $answerfactor*($factor**$exponent);
+
+	# If bubble is for correct answer (i.e., exponent = 0), and value
+	# of $answerfactor * factor**$exponent is an integer with more than
+	# 15 digits, assign $answerfactor itself as bubble value.
+	# This prevents a "use fewer digits" issue on 64bit servers
+	# when correct answer is >= 1e+16, and when correct bubble is A.
+
 	if ($exponent == 0) {
-	    $bubble_values[$ind] = $answerfactor;
-	} else { 
-	    $bubble_values[$ind] = $answerfactor*($factor**$exponent);
+	    if ($bubble_values[$ind] =~ /^-?(\d+)$/) {
+		if (length($1) > 15) {
+		    $bubble_values[$ind] = $answerfactor;
+		}
+	    }
 	}
+
 	$bubble_display[$ind] = &format_number($bubble_values[$ind],
 					       $format,$target,$safeeval);
     }




More information about the LON-CAPA-cvs mailing list