ts2c icon indicating copy to clipboard operation
ts2c copied to clipboard

Converting strings to floating-point numbers

Open jarble opened this issue 5 years ago • 1 comments

ts2c is not yet able to convert strings into floating-point numbers, though this feature would be relatively easy to implement:

var a = parseFloat("10.0");
console.log(a+2);

It may be possible to do this using using sscanf, but there may be other ways to do it.

jarble avatar Apr 07 '19 17:04 jarble

The fact that float numbers aren't yet supported is stated clearly in both README.md and COVERAGE.md. Their support is in the roadmap. There are tons of other not-yet-supported features too, but please understand that I cannot possibly implement all of them at once, no matter how "easy" they are to implement.

If you could contribute float numbers feature, I would be very grateful, but please don't forget to read how floats are handled in ES3 spec, there are important differences from how they are handled in C89 if I remember correctly. I am afraid they aren't easy to implement at all.

I keep postponing the whole number problem because this will introduce several new types into the transpilation engine, so support for inferring those types should be implemented as well as conversion between them. Also, depending on the target microprocessor architecture, numbers might be limited to certain size, and FPU might not be available at all, and this should also be handled somehow.

andrei-markeev avatar Apr 07 '19 18:04 andrei-markeev