1

The fact that Processing uses float rather than double has bothered me for a long time.

I found the actual code block in PdeEmitter.java, which is looping through an ANTLR generated AST:

// making floating point literals default to floats, not doubles
case NUM_DOUBLE:
  final String literalDouble = ast.getText().toLowerCase();
  out.print(literalDouble);
  if (Preferences.getBoolean("preproc.substitute_floats")
      && literalDouble.indexOf('d') == -1) { // permit literal doubles
    out.print("f");
  }
  dumpHiddenAfter(ast);
  break;

This leads to a frustrating amount of incompatibility when convert Processing code to standard java (all decimal literals need f added to the end, or all floats need to be renamed to double).

It looks like this can be disabled in the lib/preferences.txt:

# preprocessor: PdeEmitter.java
preproc.substitute_floats = true
#preproc.substitute_image = false
#preproc.substitute_font = false

Nevertheless, this breaks common uses of the API, since all Processing API functions were written for float.

So why is float used everywhere? I can't imagine there being a large incentive for memory usage optimization in this type of application.

Arcymag
  • 1,037
  • 1
  • 8
  • 18
  • http://stackoverflow.com/questions/417568/float-vs-double-performance – JNL Oct 07 '13 at 17:32
  • 2
    I don't know processing, but for images float offers usually enough precision. I guess the choice was made because of the lower *memory bandwidth* requirement for float (so basically speed). But you have to ask the creators to get a *definitive* answer why this choice was made. – Durandal Oct 07 '13 at 17:34

1 Answers1

2

Processing is mainly aimed at creating visual applications, rather than doing serious number crunching (which is admittedly ironic, given the name). As such, the developers don't think the precision of a double is necessary.

According to the documentation for the float datatype:

"Processing supports the 'double' datatype from Java as well, however it is not documented because none of the Processing functions use double values, which are overkill for nearly all work created in Processing and use more memory. We do not plan to support doubles, as it would require increasing the number of API functions significantly."

Peter Bloomfield
  • 5,578
  • 26
  • 37