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

WString: add toDouble #5362

Merged
merged 2 commits into from
Sep 14, 2016
Merged

Conversation

Ivan-Perez
Copy link
Contributor

@Ivan-Perez Ivan-Perez commented Sep 12, 2016

String::toFloat internally converts the string into a double (using atof) and then truncates into a
float, so why not to add a method to return the double?

`toFloat` internally converts into double and then truncates into a
float, so why not add a method to return the double?
@sandeepmistry
Copy link
Contributor

I've been trying this out today. One observation, on AVR:

sizeof(float) = 4
sizeof(double) = 4

So both floats and doubles are 32-bits. So, looks good to merge on AVR.

Will test non-AVR cores (SAM, SAMD) shortly, since we would want to port the new API to those as well.

@sandeepmistry
Copy link
Contributor

@Ivan-Perez were there some particular test sketches or values you used to determine that String::toDouble() was needed?

@Ivan-Perez
Copy link
Contributor Author

Ivan-Perez commented Sep 13, 2016

I didn't know that both float and double types were the same size. I supposed that double might be 64-bit, but I've just checked it and as you say they are the same type (reference also confirms this).

Then maybe this PR is not useful at all and can be closed without merging.

@Chris--A
Copy link
Contributor

@Ivan-Perez

Then maybe this PR is not useful at all and can be closed without merging.

Well it'll be useful for the 32-bit platforms that support a double that is larger than a float.

@sandeepmistry sandeepmistry merged commit 24cba16 into arduino:master Sep 14, 2016
@sandeepmistry
Copy link
Contributor

@Ivan-Perez thank you!

@akash73 could you please add the new toDouble function to the String Object reference.

@Ivan-Perez Ivan-Perez deleted the string-to-double branch September 14, 2016 17:45
sandeepmistry added a commit to sandeepmistry/ArduinoCore-samd that referenced this pull request Sep 14, 2016
@sandeepmistry sandeepmistry added this to the Release 1.6.12 milestone Sep 14, 2016
sandeepmistry added a commit to sandeepmistry/corelibs-arduino101 that referenced this pull request Sep 14, 2016
@sandeepmistry
Copy link
Contributor

This change has been ported to the SAMD core in arduino/ArduinoCore-samd@c7c6f70, and I've also opened a pull request for the 101 core: arduino/ArduinoCore-arc32#293.

@Ivan-Perez
Copy link
Contributor Author

Reviewing the code once again, I think that in case of failure both functions (toFloat and toDouble) should return NaN instead of 0.

In the next days I'll create a new PR to address it.

@q2dg
Copy link

q2dg commented Sep 14, 2016

Well...data types in Arduino deserve a coffe break...
#4525
#3801
#5200
...

eriknyquist pushed a commit to arduino/ArduinoCore-arc32 that referenced this pull request Sep 15, 2016
calvinatintel pushed a commit to arduino/ArduinoCore-arc32 that referenced this pull request Sep 15, 2016
calvinatintel pushed a commit to arduino/ArduinoCore-arc32 that referenced this pull request Sep 19, 2016
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

Successfully merging this pull request may close these issues.

4 participants