mys-lang / mys

The Mys programming language - an attempt to create a statically typed Python-like language that produces fast binaries. See https://mys-lang.org for more information.
Other
132 stars 5 forks source link

add int , int() and float, float() as aliases for default precision #34

Open pmp-p opened 3 years ago

pmp-p commented 3 years ago

with reasonable defaults like i32 and f32.

The main reason and it's an quite important one is that third parties C++ libraries like Panda3D or Bullet Physics can be built for simple or double float precision. So for a whole project it should be possible to set the default precision of Mys.

( also maybe up to i128/ f128 with https://bellard.org/softfp ? )

eerimoq commented 3 years ago

A goal for Mys is to be minimalistic, mainly to make that language easier to learn. Everything we add gives the user more choices and makes her less confident in what is the best way to implement a given problem.

Initially there were only int and float of machine word size. They were replaced by i8/i16/... because the user often prefers to know that their code works regardless of machine word size.

As I see it most pure Mys programs will benefit from using the fixed size types. If it turns out we can gain a huge performance improvement by introducing int and float, well, ok, I guess we have to, but if the only advantage is that C interop becomes slightly more conveniant I prefer not to add more types to Mys.

128 bits types will probably be supported as some point.

pmp-p commented 3 years ago

If it turns out we can gain a huge performance improvement by introducing int and float

it's really not about performance but interoperability instead, including safeguards when downcasting f64 / f128 to f32 ( which is already known to give very strange behaviour on bullet physic engine). Remember that doing a lot of successive float math on lesser precision than final target introduce more rounding error at each step than user would expect and may lead to bugs and bugs reports.

it is really about adding a macro to let Mys pickup at compile time the best accuracy available regarding to final target ( as if float/int where extern types provided by the third party ). It also help to avoid linking problem like https://github.com/panda3d/panda3d/issues/787

eg in Panda3D : you have Vec3f and Vec3d but user is always advised to use Vec3 instead which is remapped via include files to the matching precision choosen at build.