Add round function

This commit is contained in:
syuilo 2019-12-20 02:09:51 +09:00
parent 9bc07c1a1c
commit 1eb5578063
3 changed files with 6 additions and 0 deletions

View file

@ -2200,6 +2200,9 @@ pages:
_mod: _mod:
arg1: "A" arg1: "A"
arg2: "B" arg2: "B"
round: "少数を丸める"
_round:
arg1: "数"
eq: "AとBが同じ" eq: "AとBが同じ"
_eq: _eq:
arg1: "A" arg1: "A"

View file

@ -162,6 +162,7 @@ export class ASEvaluator {
multiply: (a: number, b: number) => a * b, multiply: (a: number, b: number) => a * b,
divide: (a: number, b: number) => a / b, divide: (a: number, b: number) => a / b,
mod: (a: number, b: number) => a % b, mod: (a: number, b: number) => a % b,
round: (a: number) => Math.round(a),
strLen: (a: string) => a.length, strLen: (a: string) => a.length,
strPick: (a: string, b: number) => a[b - 1], strPick: (a: string, b: number) => a[b - 1],
strReplace: (a: string, b: string, c: string) => a.split(b).join(c), strReplace: (a: string, b: string, c: string) => a.split(b).join(c),

View file

@ -24,6 +24,7 @@ import {
faExchangeAlt, faExchangeAlt,
faRecycle, faRecycle,
faIndent, faIndent,
faCalculator,
} from '@fortawesome/free-solid-svg-icons'; } from '@fortawesome/free-solid-svg-icons';
import { faFlag } from '@fortawesome/free-regular-svg-icons'; import { faFlag } from '@fortawesome/free-regular-svg-icons';
@ -59,6 +60,7 @@ export const funcDefs: Record<string, { in: any[]; out: any; category: string; i
multiply: { in: ['number', 'number'], out: 'number', category: 'operation', icon: faTimes, }, multiply: { in: ['number', 'number'], out: 'number', category: 'operation', icon: faTimes, },
divide: { in: ['number', 'number'], out: 'number', category: 'operation', icon: faDivide, }, divide: { in: ['number', 'number'], out: 'number', category: 'operation', icon: faDivide, },
mod: { in: ['number', 'number'], out: 'number', category: 'operation', icon: faDivide, }, mod: { in: ['number', 'number'], out: 'number', category: 'operation', icon: faDivide, },
round: { in: ['number'], out: 'number', category: 'operation', icon: faCalculator, },
eq: { in: [0, 0], out: 'boolean', category: 'comparison', icon: faEquals, }, eq: { in: [0, 0], out: 'boolean', category: 'comparison', icon: faEquals, },
notEq: { in: [0, 0], out: 'boolean', category: 'comparison', icon: faNotEqual, }, notEq: { in: [0, 0], out: 'boolean', category: 'comparison', icon: faNotEqual, },
gt: { in: ['number', 'number'], out: 'boolean', category: 'comparison', icon: faGreaterThan, }, gt: { in: ['number', 'number'], out: 'boolean', category: 'comparison', icon: faGreaterThan, },