gvergnaud / hotscript

A library of composable functions for the type-level! Transform your TypeScript types in any way you want using functions you already know.
3.38k stars 57 forks source link

Support for fractional numbers with Numbers types #87

Open TetroGem opened 1 year ago

TetroGem commented 1 year ago

Currently, trying to use a non-integer will only perform the operation on the integer portion of the number:

import { Apply, Numbers } from "hotscript";

type DoubleHalf = Apply<Numbers.Mul, [0.5, 2]>; // evaluates to 0
type DoubleTwoPointFive = Apply<Numbers.Mul, [2.5, 2]>; // evaluates to 4

Playground link

Couldn't find any mention of it on this repo, so just was wondering if this is unintentional, planned to be implemented, or not being added?

ecyrbe commented 1 year ago

It's not supported indeed. Would it be possible ? Definitely. Is it worth implementing it ? depends on use cases. The already implemented number features are already borderline useful.

To answer the question, i was not planning on adding floating point capability. But PR are welcomed. I would however suggest anyone interested in implementing it to Implement it Using a Floats namespace to not have impact on the Numbers perf