Skip to content

Instantly share code, notes, and snippets.

View iamcerebrocerberus's full-sized avatar
🎯
I'm just an algorithm with a heart 🚶‍♂️

Cerebro Cerberus iamcerebrocerberus

🎯
I'm just an algorithm with a heart 🚶‍♂️
View GitHub Profile
@iamcerebrocerberus
iamcerebrocerberus / #calculator.ts
Created June 26, 2025 00:42 — forked from tkrotoff/#calculator.ts
Calculator function using shunting yard algorithm and reverse Polish notation (RPN)
// https://gist.github.com/tkrotoff/b0b1d39da340f5fc6c5e2a79a8b6cec0
// WTF!
// parseFloat('-0') => -0 vs parseFloat(-0) => 0
// -0 === 0 => true vs Object.is(-0, 0) => false
const minus0Hack = (value: number) => (Object.is(value, -0) ? '-0' : value);
export const operators: {
[operator: string]:
| {