Created
October 2, 2020 08:20
-
-
Save sverhoeven/70101b54593ffd3972290ea9d3617777 to your computer and use it in GitHub Desktop.
run-cpp-on-web: webassembly
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<!-- Load WebAssembly module --> | |
<script type="text/javascript" src="newtonraphson.js"></script> | |
</head> | |
<body> | |
<div> | |
Function root is approximately at x = | |
<span id="answer"/> | |
</div> | |
<script> | |
// Wait for module to initialize, | |
createModule().then(({NewtonRaphson}) => { | |
// Hardcoded input values | |
const initial_guess = -4; | |
const tolerance = 0.001; | |
// Perform computation | |
const newtonraphson = new NewtonRaphson(tolerance); | |
const root = newtonraphson.solve(initial_guess); | |
// Write the value of 'root' to the tag whose 'id' is equal to "answer" | |
document.getElementById("answer").innerHTML = root.toFixed(2); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment