Skip to content

Instantly share code, notes, and snippets.

@mathdoodle
Created August 21, 2016 14:26
Show Gist options
  • Save mathdoodle/1f4778c8daa173428d96e31a875d21a3 to your computer and use it in GitHub Desktop.
Save mathdoodle/1f4778c8daa173428d96e31a875d21a3 to your computer and use it in GitHub Desktop.
Generators

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": "Generators",
"dependencies": {
"DomReady": "1.0.0",
"davinci-units": "1.3.0"
},
"operatorOverloading": true,
"name": "copy-of-copy-of-units-of measure scratchpad",
"version": "0.1.0",
"keywords": [
"BigInteger",
"BigRational"
]
}
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)
}
for(let value of ["a", "b", "c"]){
console.log(value)
}
//function *foo() {
// var x = 1 + (yield "foo");
// console.log(x);
//}
function makeIterator<T>(array: T[]){
var nextIndex = 0;
return {
next: function(){
return nextIndex < array.length ?
{value: array[nextIndex++], done: false} :
{value: undefined, done: true};
}
}
}
var it = makeIterator(['yo', 'ya']);
console.log(it.next().value); // 'yo'
console.log(it.next().value); // 'ya'
console.log(it.next().done); // true
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