Skip to content

Instantly share code, notes, and snippets.

@mathdoodle
Last active August 20, 2016 06:56
Show Gist options
  • Save mathdoodle/aa10c0b7ff36e9ded430546321618d5c to your computer and use it in GitHub Desktop.
Save mathdoodle/aa10c0b7ff36e9ded430546321618d5c to your computer and use it in GitHub Desktop.
Big Numbers

Big Numbers

Overview

The UNITS library includes data types for number theory.

These data type are a work-in-progress.

The plan is to integrate them into STEMCstudio using Operator Overloading.

BigInteger

An arbitrary size integer.

BigRational

A rational number containing two BigInteger data types.

// Create shortcuts for some values.
export const e1 = UNITS.G3.e1
export const e2 = UNITS.G3.e2
export const e3 = UNITS.G3.e3
export const meter = UNITS.G3.meter
export const kilogram = UNITS.G3.kilogram
export const second = UNITS.G3.second
export const coulomb = UNITS.G3.coulomb
export const ampere = UNITS.G3.ampere
export const kelvin = UNITS.G3.kelvin
export const mole = UNITS.G3.mole
export const candela = UNITS.G3.candela
export const newton = meter * kilogram / (second * second)
export const joule = newton * meter
export const volt = joule / coulomb
/**
* Print the HTML string without a line ending.
*/
export function print(html: string): void {
const element = document.getElementById('info');
element.innerHTML = element.innerHTML + html;
}
/**
* Print the HTML string and go to the next line.
*/
export function println(html: string): void {
print(html + '\n');
}
/**
* Print the value of a variable.
*/
export function printvar(name: string, value): void {
println('<b>' + name + '</b> => ' + value);
}
<!doctype html>
<html>
<head>
<style>
/* STYLE-MARKER */
</style>
<script src="https://jspm.io/system.js"></script>
<!-- SCRIPTS-MARKER -->
</head>
<body>
<pre id='info'></pre>
<script>
// CODE-MARKER
</script>
<script>
System.import('./script.js')
</script>
</body>
</html>
{
"description": "Big Numbers",
"dependencies": {
"DomReady": "1.0.0",
"davinci-units": "1.3.0"
},
"operatorOverloading": true,
"name": "copy-of-units-of measure scratchpad",
"version": "0.1.0",
"keywords": [
"BigInteger",
"BigRational"
],
"author": "David Geo Holmes"
}
import {e1, e2, e3} from './extras';
import {newton, kilogram, meter} from './extras';
import {println, printvar} from './extras';
/**
* Executed when the DOM is ready...
*/
function main() {
const x = UNITS.bigInt(22)
const y = UNITS.bigRat(22, 7)
printvar('x', x)
printvar('y', y)
}
function colorize(arg: any, color: string) {
return "<span style='color:"+color+"'>" + arg + "</span>";
}
// Wait for the DOM to be loaded.
function runMe() {
try {
main();
}
catch(e) {
println(colorize(e.message, 'red'));
}
}
//
DomReady.ready(runMe);
body {
background-color: #000000;
}
#info {
position: absolute;
left: 20px;
top: 20px;
font-size: 26px;
color: #00FF00;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment