Unit range question

I’ve noticed that the unit range is commonly 0-1 (zero to one)… so for instance an analog read node takes the read value and divides it by 1023 in order to remap the range from 0-1

I was wondering if there was not more merit in speeding up the math within the micro controllers by using multiply instead of divide?

https://forum.arduino.cc/index.php?topic=92684.0

i.e if you look at the analog read node:

emitValue<output_VAL>(ctx, ::analogRead(port) / 1023.);

it will perform divide every time it reads the analog port.

may I suggest maybe changing this node (and others similar to it) to maybe make use of multiply instead

where you define

const float ADCon = 1 / 1023.0;

And then use:

emitValue<output_VAL>(ctx, ::analogRead(port) * ADCon);

or something else?

Hello! Interesting idea. However, I’m seriously doubt this applies to compile-time constant multiplication and division. Modern compilers (GCC in case of XOD) are smart enough to choose the faster instrucion given that the value is known in advance.

If anyone can put an experiment with measurements which proves or rejects the hypothesis, it would be great.