70 lines
1.6 KiB
TypeScript
70 lines
1.6 KiB
TypeScript
/*
|
|
* Verrückte Turing-Maschinen — A turing complete game
|
|
* Copyright (C) 2016-2018 kcf <vidofnir@folksprak.org>
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
module lib_math
|
|
{
|
|
|
|
/**
|
|
* @desc golden ration
|
|
* @author kcf <vidofnir@folksprak.org>
|
|
*/
|
|
export const phi : float = 0.6180339887498949;
|
|
|
|
|
|
/**
|
|
* @desc square
|
|
* @author kcf <vidofnir@folksprak.org>
|
|
*/
|
|
export function sqr(x : float) : float
|
|
{
|
|
return (x*x);
|
|
}
|
|
|
|
|
|
/**
|
|
* @desc square root
|
|
* @author kcf <vidofnir@folksprak.org>
|
|
*/
|
|
export function sqrt(x : float) : float
|
|
{
|
|
return Math.sqrt(x);
|
|
}
|
|
|
|
|
|
/**
|
|
* @desc quotient of integer division
|
|
* @author kcf <vidofnir@folksprak.org>
|
|
*/
|
|
export function div(x : int, y : int) : int
|
|
{
|
|
return Math.floor(x/y);
|
|
}
|
|
|
|
|
|
/**
|
|
* @desc rest of integer division
|
|
* @author kcf <vidofnir@folksprak.org>
|
|
*/
|
|
export function mod(x : int, y : int) : int
|
|
{
|
|
return (x - (y * div(x, y)));
|
|
}
|
|
|
|
}
|
|
|