# Why are there individual keywords for different multiples of π

**URL:** <https://discourse.processing.org/t/why-are-there-individual-keywords-for-different-multiples-of/48519>\
**Category:** Beginners\
**Created:** [May 8, 2026, 1:21pm UTC](https://discourse.processing.org/t/why-are-there-individual-keywords-for-different-multiples-of/48519 "2026-05-08T13:21:00Z")\
**Posts on this page:** 1\
**Showing post:** 11

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [May 21, 2026, 6:02pm UTC](https://discourse.processing.org/t/why-are-there-individual-keywords-for-different-multiples-of/48519/11 "2026-05-21T18:02:36Z")

</div>

> [@sterretje](#):
>
> With the risk of derailing the topic

This is a separate issue from my example, but since it was raised I will clarify it.

> [@sterretje](#):
>
> you are aware that you actually never should use `==` to compare floats (and doubles)?

The context is important.  
`==` is a valid operator for floats. It is appropriate when exact equality of the stored floating-point values is the intended comparison.

It was used correctly and as intended in my example comparing the constant to a mathematical expression.

Your example uses `==` in a different context, where repeated addition accumulates floating-point approximation.

> [@sterretje](#):
>
> One would expect a match on `0.7` but as can be seen `0.7` does not exist in the output, the value is slightly higher

Experienced users would recognize the observed output as the expected result.

Expanding your code example:

> The float is stored in binary as an approximation, then converted to decimal for printing.  
> Processing’s println(f) uses Java’s default float-to-text conversion.  
> That conversion prints a short rounded decimal form, so the stored float for 0.1 appears as “0.1”.  
> The second println uses nf(f, 1, 20) to print 20 decimal places.  
> Printing 20 decimal places expands the decimal display of the stored binary float.  
> These extra digits show the decimal representation of the stored value, NOT extra precision.  
> Each += adds a binary floating-point approximation of 0.1 and stores the rounded result back in f.

```processing
// The float is stored in binary as an approximation, then converted to decimal for printing.
// Processing's println(f) uses Java's default float-to-text conversion.
// That conversion prints a short rounded decimal form, so the stored float for 0.1 appears as "0.1".
// The second println uses nf(f, 1, 20) to print 20 decimal places.
// Printing 20 decimal places expands the decimal display of the stored binary float.
// These extra digits show the decimal representation of the stored value, NOT extra precision.
// Each += adds a binary floating-point approximation of 0.1 and stores the rounded result back in f. 

float f = 0;

for(int cnt=0; cnt < 20; cnt++)
{
  f += 0.1;
  println(f);
  println(nf(f, 1, 20));
  println();
  if(f == 0.7)
    println("match");
}

```

Output:

```plaintext
0.1
0.10000000149011612000

0.2
0.20000000298023224000

0.3
0.30000001192092896000

0.4
0.40000000596046450000

0.5
0.50000000000000000000

0.6
0.60000002384185790000

0.70000005
0.70000004768371580000

0.8000001
0.80000007152557370000

0.9000001
0.90000009536743160000

1.0000001
1.00000011920928960000

1.1000001
1.10000014305114750000

1.2000002
1.20000016689300540000

1.3000002
1.30000019073486330000

1.4000002
1.40000021457672120000

1.5000002
1.50000023841857900000

1.6000003
1.60000026226043700000

1.7000003
1.70000028610229500000

1.8000003
1.80000030994415280000

1.9000003
1.90000033378601070000

2.0000002
2.00000023841857900000

```

Additional references here:  
_[Processing float values: decimal output and IEEE 754 bit patterns](https://discourse.processing.org/t/processing-float-values-decimal-output-and-ieee-754-bit-patterns/48526)_

Caveat: The expanded decimal output helps display the stored float, but typing that decimal back into code still creates a new float by converting the decimal literal to the nearest representable binary value.

> **Bonus code**
>
> ```processing
> float f=0;
> 
> for(int cnt=0; cnt < 20; cnt++)
> {
> int i = 3; // Try with 1, 2. 3, ... 
> f += 1.0/(1<<i);
> println(f);
> println(nf(f, 1, 20));
> if(f == 1.75)
> println("match");
>   
> println();
> }
> 
> ```

`:)`

---

_[View the full topic](https://discourse.processing.org/t/why-are-there-individual-keywords-for-different-multiples-of/48519)._
