Display of "numbers" and "decimals"

16 views
Skip to first unread message

Martin Jones

unread,
Oct 24, 2022, 3:07:16 AM10/24/22
to Numbas Users
Hi everyone

I am using Numbas to calculate Fourier coefficients. I have noticed that for the answers to the calculations are identified as being a mixture of numbers, rationals and decimals as shown below:

s1.png
In the solution to the question, these are formatted differently:
s2.png
I don't like how the third number is formatted as text, and I don't know why this is happening or how I can change it.

Thanks,
Martin

Christian Lawson-Perfect

unread,
Oct 24, 2022, 3:46:58 AM10/24/22
to numbas...@googlegroups.com
Hi Martin,
Can you give me a link to this question in the editor, please? 

--
You received this message because you are subscribed to the Google Groups "Numbas Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to numbas-users...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/numbas-users/b51559ba-4d86-4432-9d45-17c377e49598n%40googlegroups.com.

Martin Jones

unread,
Nov 22, 2022, 2:57:29 AM11/22/22
to Numbas Users
Christian,
Sorry for the late reply. This is the question: https://numbas.mathcentre.ac.uk/question/130741/fourier-series/
What is the difference between a general number and a "decimal"?
Regards
Martin

Christian Lawson-Perfect

unread,
Nov 22, 2022, 6:24:28 AM11/22/22
to numbas...@googlegroups.com
Thanks, that helped me identify the problem, which was quite a subtle one!
I've changed the way that variable substitution into \simplify works, and checked that the decimal value in your question is displayed the same as the others.

The difference between a 'decimal' and a 'number' value is that they use different underlying representations.
'number' is the original data type, using JavaScript's built-in floating-point number type. This doesn't cope well with extremely large or extremely small values, and small rounding errors can accumulate when you do repeated calculations.
'decimal' is a more accurate data type, which is guaranteed to be correct to 40 significant figures. The only reason it's not used everywhere is that it could break old questions written before it was introduced.

There are a couple of other data types representing numbers: 'integer' and 'rational'. As far as is possible without breaking backwards-compatibility, Numbas tries to use the best data type to represent a number, based on the operations you perform on it. That's why you see a mix of data types in your variables.


Martin Jones

unread,
Nov 23, 2022, 3:46:48 AM11/23/22
to Numbas Users
Thanks Christian!

It looks good on the advice section now, but (just to be picky) it still looks slightly different on the revealed answer:
n1.png

I read the documentation. Is there a reason why "2-2/pi" is interpreted as a number, but "2/1-2/pi" is interpreted as a decimal, even though they are the same number?!

Martin

Christian Lawson-Perfect

unread,
Nov 23, 2022, 3:49:19 AM11/23/22
to numbas...@googlegroups.com
Ah rats, that's another case I hadn't thought of! Now I know what I'm spending this morning doing, at least!


Christian Lawson-Perfect

unread,
Nov 23, 2022, 10:57:53 AM11/23/22
to numbas...@googlegroups.com
OK, I've ended up spending the whole day resolving this!
I've made sure that decimal values are treated correctly throughout the rendering pipeline, so they won't be implicitly converted down to floats, or treated as plain text. This is quite a big change, so I'm leaving it in the development branch, where I'll do some more testing.
Reply all
Reply to author
Forward
0 new messages