-
-
Notifications
You must be signed in to change notification settings - Fork 78
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
Instantiating from floats #32
Comments
Hi 👋 I apologize if the README is not clear enough on this point. The suggestion really is to not use floats at all, as you'll most likely be bitten at some point by a rounding issue. Floats can accurately represent integers (up to a point), halves, quarters, etc. Pretty much everything else is an approximation, that may or may not give the value you expect when converted to a string. Example from this IEEE 754 converter:
As you can see though, This is why the README advocates to deal with integer or string values everywhere outside Back to your question.In your case, you have a What you should really do is refactor your codebase to only ever deal with integers or strings. That is, if you care about precision (when dealing with monetary values, for example).
If you really care about precision, you should not be using said library. Floating point values are inherently approximations in mose cases, and are not there for this purpose. If you want to deal with large values but do not care about precision, then it may be OK to use the library in question. But then I would question why you'd need If you give me the name of the library in question, I can probably better clarify this point. Can we improve the README?If there's some changes in wording I can make to the README to make this more clear, please let me know! |
Thank you for your thorough and helpful reply :-) The library I'm using is this one: https://github.com/cyjoelchen/php-sweph Which is a PHP extension of this C library: https://www.astro.com/swisseph/swephinfo_e.htm The underlying C lib uses As for overall precision, I would like my codebase to maintain the same level of precision as the Swiss Ephemeris library. |
Thanks for the link! PHP's floats are Your library deals with planetary positions, so inherently approximative. Floating-point values are a very good fit for this. Therefore I stand by my statement above, you may not need brick/math at all? The only advantage of using brick/math to perform further calculations on your floating point values, is that you won't accumulate imprecision. At the cost of speed! |
That's my concern because I do perform calculations on the returned data. Even though, as you stated, the source data is approximate anyway, I still want to avoid moving further away from those approximations by using the Do floats always approximate consistently? I would think they must, but this is part of my hesitation in using them and why I'm drawn to brick/math instead. |
You're getting me out of my comfort zone ;-) I would suggest you try the same set of computations with both |
The docs/readme states:
I'm looking to implement this library throughout my existing application, but am using
float
types in my method signatures. According to the above, it sounds like I should either pass in strings instead, or convert the floats to strings.So one of?
EDIT: I should mention that the floats I'm working with are provided from another library. In other words, I am not creating these values myself, but instead performing calculations on generated ones.
The text was updated successfully, but these errors were encountered: