Skip to content

Sig fig context#1474

Open
pstaabp wants to merge 19 commits into
openwebwork:PG-2.21from
pstaabp:sig-fig-context
Open

Sig fig context#1474
pstaabp wants to merge 19 commits into
openwebwork:PG-2.21from
pstaabp:sig-fig-context

Conversation

@pstaabp

@pstaabp pstaabp commented Jul 21, 2026

Copy link
Copy Markdown
Member

This creates a context for Significant Figures and huge thanks to @dpvc for all the help and @sfiedle1 for ideas, code and other suggestions.

In short, this handles the creation of a number type that keeps track of the number of its significant figures. Although the number is stored as a floating point, the string method rounds to the appropriate number of significant figures.

Here are a few features:

  • The operations +, -, *, /, ^ are all defined with operations between SigFig numbers. See Sig fig improvements pstaabp/pg#25 for a post from @dpvc about thoughts about this.
  • There is ability to define a number with infinite number of significant figures. This would allow an operation like 1.23^3 to result in an expected number with 3 sigfigs instead of 1, since 3 only has 1 sig fig.
  • There are two flags that allow authors to specify some partial credit as well as informational messages if a student answer is either close to the real answer with correct number of sig figs OR the correct answer with an incorrect number of sigfigs. Note: I think these flags can use some better names.
  • There is a LimitedSignificantFigures context which disallows computations similar to other contexts.
  • Using the contextExtensions.pl macro, problems using both SignificantFigures and Units can be used together.

There are two test suites. significant_figures.t tests only numbers and operations between numbers. significant_figures_units.t includes some simple tests for numbers with units.

I have attached 4 sample problems.

  1. This has addition, subtraction and multiplication of 2 numbers.
  2. This has a basic number with units.
  3. This shows the two flags mentioned above.
  4. An example with the LimitedSignificantFigure context.

setsig_fig.zip

If we can get this into 2.21, that would be great. It doesn't affect anything else. If not, I'll retarget to develop.

Also, for historical purposes, there is other discussion: pstaabp/pull/25 pstaabp/pull/32, pstaabp/pull/34 and pstaabp/pull/36

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants