gphoto / libgphoto2

The libgphoto2 camera access and control library.
GNU Lesser General Public License v2.1
1.02k stars 322 forks source link

Floating point issue with GP_WIDGET_RANGE widgets #108

Open nmrmak opened 7 years ago

nmrmak commented 7 years ago

Hi,

There seems to be a problem with setting range widgets such as flashexposurecompensation on Nikon D7000.

For example, it is not possible to run something like: gp_widget_set_value(widget, -7.0/3); when evstep is 1/3, because: -7.0/3 equals -2.333333254 step equals 0.3333333433

Float values are here represented with 10 digits precision, enough to show the problem.

So it would work with -2.3333333433, but that's not what -7.0/3 evaluates to. I could wrap this setting in an elaborate function that would deal with steps, but that just doesn't seem like an elegant way to use the library.

Is there a better way to deal with floats in libgphoto2?

Feel free to let me know if this is to be closed as "not a bug", and thank you for your great effort with libgphoto2!

Thanks in advance, Nebojsa

msmeissn commented 7 years ago

hmm. the value you pass in via gp_widget_set_value is not checked internally against the range/step settings. the multiplication *6.0 might result in -13.9999999 later on though instead of -14

where do you actually see troubles?

nmrmak commented 7 years ago

The problem can be reproduced by trying to set evstep to minus 7 thirds programatically, like so: gp_widget_set_value(widget, -7.0/3)