Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
pmp-p opened this issue Jan 30, 2021 · 2 comments
Open

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

pmp-p opened this issue Jan 30, 2021 · 2 comments

Comments

@pmp-p
Copy link
Collaborator

pmp-p commented Jan 30, 2021

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
Copy link
Collaborator

eerimoq commented Jan 30, 2021

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
Copy link
Collaborator Author

pmp-p commented Jan 30, 2021

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 panda3d/panda3d#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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants