Closed giumas closed 8 years ago
The decision for using floats instead of double is severalfold:
GLAPI void GLAPIENTRY gluNurbsCurve (GLUnurbs* nurb, GLint knotCount, GLfloat *knots, GLint stride, GLfloat *control, GLint order, GLenum type)
that allows one to draw arbitrary splines. As you can see, the function takes GLfloat
for knots and control points. Thus, I had to implement the struct tsBSpline
with floats instead of doubles.
tsBSpline
requires (100 * 2 * 4) + (100 + 4) * 4 = 800 + 416 = 1216
bytes in case of floats (excluding fields like deg
, order
, ...). On the other hand, using doubles instead of floats doubles the size. That is, 2432
bytes for the given example! Since TinySpline has been designed to work on microcontrollers---such as Arduino Uno---as well, using floats instead of doubles is a real thing.Does your code have real problems with floats that do not occur with doubles? If yes, could you please give me an example?
The first example that comes in my mind is about using geographic coordinates for the position of the control points.
Do you mean latitude and longitude?
yes, the float accuracy is often not enough.
If I'm correct, then there are 180 latitude and 360 longitude? That gives you about 4 well defined decimal places, for instance 150.0034. How many decimal places do you need?
That is a really nice article. So, how many decimal places do you need?
I believe that a general GIS application supports at least the seventh decimal place.
According to http://stackoverflow.com/questions/13542944/how-many-significant-digits-have-floats-and-doubles-in-java a single precision float has 6 to 9 (about 7 on average) decimal points (I'm pretty sure they have the same precision in C as in Java). I can't say if it is enough for your application but changing the interface to doubles (or using macros to give someone a choice) makes things really hard. It not only affects the C interface but also the C++, Java, Python, etc. interfaces.
I can't say if it is enough for your application but changing the interface to doubles (or using macros to give someone a choice) makes things really hard. It not only affects the C interface but also the C++, Java, Python, etc. interfaces.
I have already tweaked it using a macro. Since I only use the C library, it is relatively simple.
I usually open a ticket when I believe that a problem can be common to other users that want to use a library. Being float-based is a relevant library's feature that is not cleared stated in the README file.
Being float-based is a relevant library's feature that is not cleared stated in the README file.
I will consider it when adding more text to the documentation, thanks. I think we can close this issue for now?
Of course
I usually open a ticket when I believe that a problem can be common to other users that want to use a library.
Thanks for that. So far, you added some valuable changes to TinySpline.
The current implementation is
float
-based.This represents a limiting factor for applications where the precision provided by
float
is not enough: