MRtrix3 / mrtrix3

MRtrix3 provides a set of tools to perform various advanced diffusion MRI analyses, including constrained spherical deconvolution (CSD), probabilistic tractography, track-density imaging, and apparent fibre density
http://www.mrtrix.org
Mozilla Public License 2.0
291 stars 179 forks source link

New class combining float & string representations #2858

Open Lestropie opened 6 months ago

Lestropie commented 6 months ago

This comes to mind all the time but have never had the chance to address it; just looked now and seems it isn't listed.

Quite often, in both GUI and headless applications, a floating-point value is provided by the user. This is converted from a string into a floating-point representation. It is quite often then converted back to a string; maybe as terminal feedback, as an entry in key-value pairs in a file, or in a GUI text box. This promotes the floating-point imprecision back to the user.

The basic idea is to have a class that internally stores both the binary floating-point representation and the string representation of a floating-point number. The value can be set using either one, and the other representation is immediately generated. Whenever the floating-point value or the string representation is requested, no conversion need occur. This would need to replace instances of floating-point value usage; primarily whenever an input may come from a user, but arguably also if floating-point values are read from an input file and those values could be recapitulated in a text output somewhere.