Jump to content

Safe addition: Difference between revisions

m
m (syntax highlighting fixup automation)
m (→‎{{header|Wren}}: Minor tidy)
Line 997:
 
However, if Wren is embedded in a suitable C program, then we can ask the latter to call it for us and pass back the result.
<syntaxhighlight lang="ecmascriptwren">/* safe_additionSafe_addition.wren */
class Interval {
construct new(lower, upper) {
Line 1,026:
 
Note that Wren's built-in print statement never displays numbers with more than 14 digit accuracy. However, if the interval bounds had been displayed directly from C with 17 digit accuracy (the maximum for the 'double' type), there would have been a marginal difference between them, namely: [1.2299999999999998, 1.2300000000000002].
<syntaxhighlight lang="c">#include/* <stdlibgcc Safe_addition.h>c -o Safe_addition -lwren -lm */
 
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
Line 1,092 ⟶ 1,094:
WrenVM* vm = wrenNewVM(&config);
const char* module = "main";
const char* fileName = "safe_additionSafe_addition.wren";
char *script = readFile(fileName);
WrenInterpretResult result = wrenInterpret(vm, module, script);
9,485

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.