🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

158 total messages Page 1 of 4 Started by fir Tue, 27 Oct 2026 10:53
Page 1 of 4 • 158 total messages
.5 against 0.5f
#845
Author: fir
Date: Tue, 27 Oct 2026 10:53
13 lines
1690 bytes
if ai generates me some functions it puts everywhere this f at the and
yet it add zeros so instead of .1 i got 0.1f

and i obviously dont like it

i write hvever some codes when i need speed so the question is may it 
give some difference?

i mean .1 maybe can be treated as doube constants so mabe occupies some 
more memory (?) or uses some casting in coplutations (?)


i doubt it probably it makes difference but im strictly not sure
Re: .5 against 0.5f
#863
Author: Steven G. Kargl
Date: Tue, 27 Oct 2026 17:45
44 lines
2267 bytes
On Tue, 27 Oct 2026 11:53:55 +0100, fir wrote:

> if ai generates me some functions it puts everywhere this f at the and
> yet it add zeros so instead of .1 i got 0.1f
> 
> and i obviously dont like it
> 
> i write hvever some codes when i need speed so the question is may it
> give some difference?
> 
> i mean .1 maybe can be treated as doube constants so mabe occupies some
> more memory (?) or uses some casting in coplutations (?)
> 
> 
> i doubt it probably it makes difference but im strictly not sure

The leading zero in 0.1 or 0.1f is irrelevant, but (to me) makes 
code easier to read.  The difference between 0.1 and 0.1f with
their binary representations is a another matter.

#include <stdio.h>

int
main(void)
{
   double d;
   d = 0.1f;
   printf("%.13a\n", d);
   d = 0.1;
   printf("%.13a\n", d);
   return (0);
}

% cc -o z t.c && ./z
0x1.99999a0000000p-4
0x1.999999999999ap-4

The real number is 0.1 is not exactly representable in a binary
floating point format.  See

https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html

-- 
steve
Re: .5 against 0.5f
#865
Author: fir
Date: Tue, 27 Oct 2026 17:50
53 lines
2867 bytes
Steven G. Kargl pisze:
> On Tue, 27 Oct 2026 11:53:55 +0100, fir wrote:
> 
>> if ai generates me some functions it puts everywhere this f at the and
>> yet it add zeros so instead of .1 i got 0.1f
>>
>> and i obviously dont like it
>>
>> i write hvever some codes when i need speed so the question is may it
>> give some difference?
>>
>> i mean .1 maybe can be treated as doube constants so mabe occupies some
>> more memory (?) or uses some casting in coplutations (?)
>>
>>
>> i doubt it probably it makes difference but im strictly not sure
> 
> The leading zero in 0.1 or 0.1f is irrelevant, but (to me) makes
> code easier to read.  The difference between 0.1 and 0.1f with
> their binary representations is a another matter.
> 
> #include <stdio.h>
> 
> int
> main(void)
> {
>     double d;
>     d = 0.1f;
>     printf("%.13a\n", d);
>     d = 0.1;
>     printf("%.13a\n", d);
>     return (0);
> }
> 
> % cc -o z t.c && ./z
> 0x1.99999a0000000p-4
> 0x1.999999999999ap-4
> 
> The real number is 0.1 is not exactly representable in a binary
> floating point format.  See
> 
> https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html
> 


but the question is: can using .1 instead of 0.1f make me any harm in 
code? like things get slower in runtime? (assuming i use floats in code
not doubles, and the code is a bit time critical like rasterisation goes 
on floats)  why the ai so maniacally puts that f?


i gues the answer is NOT but maybe soem can show at least one case it 
could be worse?
Re: .5 against 0.5f
#867
Author: Scott Lurndal
Date: Tue, 27 Oct 2026 18:40
51 lines
2266 bytes
"Steven G. Kargl" <sgk@REMOVEtroutmask.apl.washington.edu> writes:
>On Tue, 27 Oct 2026 11:53:55 +0100, fir wrote:
>
>> if ai generates me some functions it puts everywhere this f at the and
>> yet it add zeros so instead of .1 i got 0.1f
>> 
>> and i obviously dont like it
>> 
>> i write hvever some codes when i need speed so the question is may it
>> give some difference?
>> 
>> i mean .1 maybe can be treated as doube constants so mabe occupies some
>> more memory (?) or uses some casting in coplutations (?)
>> 
>> 
>> i doubt it probably it makes difference but im strictly not sure
>
>The leading zero in 0.1 or 0.1f is irrelevant, but (to me) makes 
>code easier to read.  The difference between 0.1 and 0.1f with
>their binary representations is a another matter.
>
>#include <stdio.h>
>
>int
>main(void)
>{
>   double d;
>   d = 0.1f;
>   printf("%.13a\n", d);
>   d = 0.1;
>   printf("%.13a\n", d);
>   return (0);
>}
>
>% cc -o z t.c && ./z
>0x1.99999a0000000p-4
>0x1.999999999999ap-4
>
>The real number is 0.1 is not exactly representable in a binary
>floating point format.  See
>
>https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html

I ordered a couple of blu-rays from amazon last week, and the
confirmation email had the following for the total price:

   Total
   75.71000000000001 USD

Appears they may be using FP instead of integer fixed point arithmetic
for pricing.
Re: .5 against 0.5f
#868
Author: Steven G. Kargl
Date: Tue, 27 Oct 2026 19:01
57 lines
3183 bytes
On Tue, 27 Oct 2026 18:50:09 +0100, fir wrote:

> Steven G. Kargl pisze:
>> On Tue, 27 Oct 2026 11:53:55 +0100, fir wrote:
>> 
>>> if ai generates me some functions it puts everywhere this f at the and
>>> yet it add zeros so instead of .1 i got 0.1f
>>>
>>> and i obviously dont like it
>>>
>>> i write hvever some codes when i need speed so the question is may it
>>> give some difference?
>>>
>>> i mean .1 maybe can be treated as doube constants so mabe occupies
>>> some more memory (?) or uses some casting in coplutations (?)
>>>
>>>
>>> i doubt it probably it makes difference but im strictly not sure
>> 
>> The leading zero in 0.1 or 0.1f is irrelevant, but (to me) makes code
>> easier to read.  The difference between 0.1 and 0.1f with their binary
>> representations is a another matter.
>> 
>> #include <stdio.h>
>> 
>> int main(void)
>> {
>>     double d;
>>     d = 0.1f; printf("%.13a\n", d);
>>     d = 0.1; printf("%.13a\n", d);
>>     return (0);
>> }
>> 
>> % cc -o z t.c && ./z 0x1.99999a0000000p-4 0x1.999999999999ap-4
>> 
>> The real number is 0.1 is not exactly representable in a binary
>> floating point format.  See
>> 
>> https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html
>>
   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   Here is your answer.

> but the question is: can using .1 instead of 0.1f make me any harm in
> code? like things get slower in runtime? (assuming i use floats in code
> not doubles, and the code is a bit time critical like rasterisation goes
> on floats)  why the ai so maniacally puts that f?

Without seeing code and not knowing whether you are concerned with
the propagation of floating point errors, the only answer that one can
give for your first two questions is "yes, no, maybe".

AI is likely appending the f because you instructed AI to use a
float type.  Why not ask AI why it appends the f?

-- 
steve
Re: .5 against 0.5f
#869
Author: fir
Date: Tue, 27 Oct 2026 19:15
77 lines
4022 bytes
Steven G. Kargl pisze:
> On Tue, 27 Oct 2026 18:50:09 +0100, fir wrote:
> 
>> Steven G. Kargl pisze:
>>> On Tue, 27 Oct 2026 11:53:55 +0100, fir wrote:
>>>
>>>> if ai generates me some functions it puts everywhere this f at the and
>>>> yet it add zeros so instead of .1 i got 0.1f
>>>>
>>>> and i obviously dont like it
>>>>
>>>> i write hvever some codes when i need speed so the question is may it
>>>> give some difference?
>>>>
>>>> i mean .1 maybe can be treated as doube constants so mabe occupies
>>>> some more memory (?) or uses some casting in coplutations (?)
>>>>
>>>>
>>>> i doubt it probably it makes difference but im strictly not sure
>>>
>>> The leading zero in 0.1 or 0.1f is irrelevant, but (to me) makes code
>>> easier to read.  The difference between 0.1 and 0.1f with their binary
>>> representations is a another matter.
>>>
>>> #include <stdio.h>
>>>
>>> int main(void)
>>> {
>>>      double d;
>>>      d = 0.1f; printf("%.13a\n", d);
>>>      d = 0.1; printf("%.13a\n", d);
>>>      return (0);
>>> }
>>>
>>> % cc -o z t.c && ./z 0x1.99999a0000000p-4 0x1.999999999999ap-4
>>>
>>> The real number is 0.1 is not exactly representable in a binary
>>> floating point format.  See
>>>
>>> https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html
>>>
>     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>     Here is your answer.
> 
>> but the question is: can using .1 instead of 0.1f make me any harm in
>> code? like things get slower in runtime? (assuming i use floats in code
>> not doubles, and the code is a bit time critical like rasterisation goes
>> on floats)  why the ai so maniacally puts that f?
> 
> Without seeing code and not knowing whether you are concerned with
> the propagation of floating point errors, the only answer that one can
> give for your first two questions is "yes, no, maybe".
> 
> AI is likely appending the f because you instructed AI to use a
> float type.  Why not ask AI why it appends the f?
> 
it says: i add f that the number would be float type instead of double


float x=a*1.5;

it also says in such above case the multiplication would be in double 
then converted to float - bout for me its hard to belive

(i some cases ai not quite tells the truth and i cant easily validate it)

it also not gives stright answe if pushed - it says more liek id depends 
on flags, compiler may or may

so this is no good answer

(and i asume there may be soem simple answer here i dont know
(and i suspect its rather - no it will generate float no silly conversions

if no that would be bad)

Re: .5 against 0.5f
#871
Author: Tim Rentsch
Date: Tue, 27 Oct 2026 19:29
13 lines
1643 bytes
scott@slp53.sl.home (Scott Lurndal) writes:

> I ordered a couple of blu-rays from amazon last week, and the
> confirmation email had the following for the total price:
>
>    Total
>    75.71000000000001 USD
>
> Appears they may be using FP instead of integer fixed point arithmetic
> for pricing.

Send them an email saying you were overcharged and want a refund
of 0.000000000001 cents.  ;)
Re: .5 against 0.5f
#909
Author: Michael S
Date: Tue, 27 Oct 2026 19:43
60 lines
2977 bytes
On Tue, 27 Oct 2026 18:40:52 GMT
scott@slp53.sl.home (Scott Lurndal) wrote:

> "Steven G. Kargl" <sgk@REMOVEtroutmask.apl.washington.edu> writes:
> >On Tue, 27 Oct 2026 11:53:55 +0100, fir wrote:
> >  
> >> if ai generates me some functions it puts everywhere this f at the
> >> and yet it add zeros so instead of .1 i got 0.1f
> >> 
> >> and i obviously dont like it
> >> 
> >> i write hvever some codes when i need speed so the question is may
> >> it give some difference?
> >> 
> >> i mean .1 maybe can be treated as doube constants so mabe occupies
> >> some more memory (?) or uses some casting in coplutations (?)
> >> 
> >> 
> >> i doubt it probably it makes difference but im strictly not sure  
> >
> >The leading zero in 0.1 or 0.1f is irrelevant, but (to me) makes 
> >code easier to read.  The difference between 0.1 and 0.1f with
> >their binary representations is a another matter.
> >
> >#include <stdio.h>
> >
> >int
> >main(void)
> >{
> >   double d;
> >   d = 0.1f;
> >   printf("%.13a\n", d);
> >   d = 0.1;
> >   printf("%.13a\n", d);
> >   return (0);
> >}
> >
> >% cc -o z t.c && ./z
> >0x1.99999a0000000p-4
> >0x1.999999999999ap-4
> >
> >The real number is 0.1 is not exactly representable in a binary
> >floating point format.  See
> >
> >https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html  
> 
> I ordered a couple of blu-rays from amazon last week, and the
> confirmation email had the following for the total price:
> 
>    Total
>    75.71000000000001 USD
> 
> Appears they may be using FP instead of integer fixed point arithmetic
> for pricing.

At least, unlike favorite AI of fir, Amazon was not using
single-precision.


Re: .5 against 0.5f
#873
Author: Steven G. Kargl
Date: Tue, 27 Oct 2026 19:54
35 lines
2485 bytes
On Tue, 27 Oct 2026 20:15:20 +0100, fir wrote:

> Steven G. Kargl pisze:
>> On Tue, 27 Oct 2026 18:50:09 +0100, fir wrote:
>> 
>>> Steven G. Kargl pisze:
>>>> On Tue, 27 Oct 2026 11:53:55 +0100, fir wrote:

(snip)

>>> but the question is: can using .1 instead of 0.1f make me any harm in
>>> code? like things get slower in runtime? (assuming i use floats in
>>> code not doubles, and the code is a bit time critical like
>>> rasterisation goes on floats)  why the ai so maniacally puts that f?
>> 
>> Without seeing code and not knowing whether you are concerned with the
>> propagation of floating point errors, the only answer that one can give
>> for your first two questions is "yes, no, maybe".
>> 
>> AI is likely appending the f because you instructed AI to use a float
>> type.  Why not ask AI why it appends the f?
>> 
> it says: i add f that the number would be float type instead of double
> 
> float x=a*1.5;
> 
> it also says in such above case the multiplication would be in double
> then converted to float - bout for me its hard to belive
> 

I do not know where to begin to address the above.  Perhaps,
find a copy of K&R to read.

-- 
steve
Re: .5 against 0.5f
#874
Author: Kaz Kylheku
Date: Tue, 27 Oct 2026 19:58
27 lines
2155 bytes
On 2026-10-27, Steven G. Kargl <sgk@REMOVEtroutmask.apl.washington.edu> wrote:
> % cc -o z t.c && ./z
> 0x1.99999a0000000p-4
> 0x1.999999999999ap-4
>
> The real number is 0.1 is not exactly representable in a binary
> floating point format.

The real number 0.1 has a worse approximation in float than double,
(if those are not the same size).

However, every representation in float is supposed to be available
in double: float to double conversion is lossless.

If you write double d = 0.1f you are essentially saying you want d to
take on that approximation of 0.1 that is available in float,
rather than a possibly better one available in double.

The abstract semantics is that 0.1f is a constant of type float.
The actual semantics may be that the compiler notices that the
float is used as an initialize for a double, and so just convert
to a double constant of the same value.

-- 
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
Re: .5 against 0.5f
#876
Author: Michael S
Date: Tue, 27 Oct 2026 20:05
71 lines
3355 bytes
On Tue, 27 Oct 2026 21:43:42 +0200
Michael S <already5chosen@yahoo.com> wrote:

> On Tue, 27 Oct 2026 18:40:52 GMT
> scott@slp53.sl.home (Scott Lurndal) wrote:
> 
> > "Steven G. Kargl" <sgk@REMOVEtroutmask.apl.washington.edu> writes:  
> > >On Tue, 27 Oct 2026 11:53:55 +0100, fir wrote:
> > >    
> > >> if ai generates me some functions it puts everywhere this f at
> > >> the and yet it add zeros so instead of .1 i got 0.1f
> > >> 
> > >> and i obviously dont like it
> > >> 
> > >> i write hvever some codes when i need speed so the question is
> > >> may it give some difference?
> > >> 
> > >> i mean .1 maybe can be treated as doube constants so mabe
> > >> occupies some more memory (?) or uses some casting in
> > >> coplutations (?)
> > >> 
> > >> 
> > >> i doubt it probably it makes difference but im strictly not sure
> > >>    
> > >
> > >The leading zero in 0.1 or 0.1f is irrelevant, but (to me) makes 
> > >code easier to read.  The difference between 0.1 and 0.1f with
> > >their binary representations is a another matter.
> > >
> > >#include <stdio.h>
> > >
> > >int
> > >main(void)
> > >{
> > >   double d;
> > >   d = 0.1f;
> > >   printf("%.13a\n", d);
> > >   d = 0.1;
> > >   printf("%.13a\n", d);
> > >   return (0);
> > >}
> > >
> > >% cc -o z t.c && ./z
> > >0x1.99999a0000000p-4
> > >0x1.999999999999ap-4
> > >
> > >The real number is 0.1 is not exactly representable in a binary
> > >floating point format.  See
> > >
> > >https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html    
> > 
> > I ordered a couple of blu-rays from amazon last week, and the
> > confirmation email had the following for the total price:
> > 
> >    Total
> >    75.71000000000001 USD
> > 
> > Appears they may be using FP instead of integer fixed point
> > arithmetic for pricing.  
> 
> At least, unlike favorite AI of fir, Amazon was not using
> single-precision.
> 
> 
> 

BTW, 75.71000000000001 looks like 67 * 1.13 in IEEE binary64, but
rounded up rather than to nearest.


Re: .5 against 0.5f
#875
Author: Kaz Kylheku
Date: Tue, 27 Oct 2026 20:05
47 lines
2934 bytes
On 2026-10-27, Scott Lurndal <scott@slp53.sl.home> wrote:
> I ordered a couple of blu-rays from amazon last week, and the
> confirmation email had the following for the total price:
>
>    Total
>    75.71000000000001 USD
>
> Appears they may be using FP instead of integer fixed point arithmetic
> for pricing.

That reminds of a joke I have in the TXR Lisp fortune module,
intended for displaying a random quip at REPL startup.

Oh, look, I got it after just a couple of tries:

This is the TXR Lisp interactive listener of TXR 302.
Quit with :quit or Ctrl-D on an empty line. Ctrl-X ? for cheatsheet.
1> (quip)
"Coding around Unicode grapheme clusters is a character-building exercise."
2> (quip)
"defmicro: error: expansion is larger than original form: switch to defmacro."
3> (prinl (quip))
"This could be the year of the TXR desktop; I can feel it!"
"This could be the year of the TXR desktop; I can feel it!"
4> (put-line (quip))
TXR kind of supports IEEE 754.00000000000003 floating-point.
t

:)

FP is fine for pricing: look at how ridiculously close to 75.71
the above approximation is. You just have to make sure never to
let enough error accumulate so that an intermediate value
is suddenly closer to the wrong penny value than the right one.
(Actually you don't even want to get anywhere near that level
of error.)

If all your system does is take a value from a ledger, do a few simple
calcluations on it, then round it to the best approximation of the nearest
penny before recording back into the ledger, you are fine.  You then just have
to be careful about converting the values to digits.


-- 
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
Re: .5 against 0.5f
#878
Author: Chris M. Thomasson
Date: Tue, 27 Oct 2026 20:08
19 lines
1807 bytes
On 10/27/2026 3:53 AM, fir wrote:
> if ai generates me some functions it puts everywhere this f at the and
> yet it add zeros so instead of .1 i got 0.1f
> 
> and i obviously dont like it
> 
> i write hvever some codes when i need speed so the question is may it 
> give some difference?
> 
> i mean .1 maybe can be treated as doube constants so mabe occupies some 
> more memory (?) or uses some casting in coplutations (?)
> 
> 
> i doubt it probably it makes difference but im strictly not sure

Why not ask the ai, again... ;^)

0.1f == .1f
Re: .5 against 0.5f
#877
Author: Chris M. Thomasson
Date: Tue, 27 Oct 2026 20:10
38 lines
2848 bytes
On 10/27/2026 12:54 PM, Steven G. Kargl wrote:
> On Tue, 27 Oct 2026 20:15:20 +0100, fir wrote:
> 
>> Steven G. Kargl pisze:
>>> On Tue, 27 Oct 2026 18:50:09 +0100, fir wrote:
>>>
>>>> Steven G. Kargl pisze:
>>>>> On Tue, 27 Oct 2026 11:53:55 +0100, fir wrote:
> 
> (snip)
> 
>>>> but the question is: can using .1 instead of 0.1f make me any harm in
>>>> code? like things get slower in runtime? (assuming i use floats in
>>>> code not doubles, and the code is a bit time critical like
>>>> rasterisation goes on floats)  why the ai so maniacally puts that f?
>>>
>>> Without seeing code and not knowing whether you are concerned with the
>>> propagation of floating point errors, the only answer that one can give
>>> for your first two questions is "yes, no, maybe".
>>>
>>> AI is likely appending the f because you instructed AI to use a float
>>> type.  Why not ask AI why it appends the f?
>>>
>> it says: i add f that the number would be float type instead of double
>>
>> float x=a*1.5;
>>
>> it also says in such above case the multiplication would be in double
>> then converted to float - bout for me its hard to belive
>>
> 
> I do not know where to begin to address the above.  Perhaps,
> find a copy of K&R to read.
> 

Oh, but the ai is his nest of books. Almost like the tommyknockers from 
Stephen King. The residents of Haven started making things that they did 
not understand at all.
Re: .5 against 0.5f
#880
Author: Chris M. Thomasson
Date: Tue, 27 Oct 2026 20:11
16 lines
1814 bytes
On 10/27/2026 12:29 PM, Tim Rentsch wrote:
> scott@slp53.sl.home (Scott Lurndal) writes:
> 
>> I ordered a couple of blu-rays from amazon last week, and the
>> confirmation email had the following for the total price:
>>
>>     Total
>>     75.71000000000001 USD
>>
>> Appears they may be using FP instead of integer fixed point arithmetic
>> for pricing.
> 
> Send them an email saying you were overcharged and want a refund
> of 0.000000000001 cents.  ;)

ROFL!
Re: .5 against 0.5f
#881
Author: Chris M. Thomasson
Date: Tue, 27 Oct 2026 20:25
19 lines
1967 bytes
On 10/27/2026 1:11 PM, Chris M. Thomasson wrote:
> On 10/27/2026 12:29 PM, Tim Rentsch wrote:
>> scott@slp53.sl.home (Scott Lurndal) writes:
>>
>>> I ordered a couple of blu-rays from amazon last week, and the
>>> confirmation email had the following for the total price:
>>>
>>>     Total
>>>     75.71000000000001 USD
>>>
>>> Appears they may be using FP instead of integer fixed point arithmetic
>>> for pricing.
>>
>> Send them an email saying you were overcharged and want a refund
>> of 0.000000000001 cents.  ;)
> 
> ROFL!

Must have just watched superman 3? ;^)
Re: .5 against 0.5f
#883
Author: David Brown
Date: Tue, 27 Oct 2026 20:35
46 lines
3224 bytes
On 27/10/2026 20:54, Steven G. Kargl wrote:
> On Tue, 27 Oct 2026 20:15:20 +0100, fir wrote:
> 
>> Steven G. Kargl pisze:
>>> On Tue, 27 Oct 2026 18:50:09 +0100, fir wrote:
>>>
>>>> Steven G. Kargl pisze:
>>>>> On Tue, 27 Oct 2026 11:53:55 +0100, fir wrote:
> 
> (snip)
> 
>>>> but the question is: can using .1 instead of 0.1f make me any harm in
>>>> code? like things get slower in runtime? (assuming i use floats in
>>>> code not doubles, and the code is a bit time critical like
>>>> rasterisation goes on floats)  why the ai so maniacally puts that f?
>>>
>>> Without seeing code and not knowing whether you are concerned with the
>>> propagation of floating point errors, the only answer that one can give
>>> for your first two questions is "yes, no, maybe".
>>>
>>> AI is likely appending the f because you instructed AI to use a float
>>> type.  Why not ask AI why it appends the f?
>>>
>> it says: i add f that the number would be float type instead of double
>>
>> float x=a*1.5;
>>
>> it also says in such above case the multiplication would be in double
>> then converted to float - bout for me its hard to belive
>>
> 
> I do not know where to begin to address the above.  Perhaps,
> find a copy of K&R to read.
> 

For your benefit (not for Fir's), the multiplication of "a * 1.5" would 
be done in double precision (unless "a" is a "long double").  The 
resulting double value would then be converted to a single-precision float.

Whether "a * 1.5f" is done as single (float) or double depends on the 
type of "a" - if it is a "double", then the float value 1.5f gets 
converted to a double (and may be slightly different from 1.5) and the 
multiplication is done as double precision.  If "a" is of type "float", 
then the multiplication is done as single precision.

Re: .5 against 0.5f
#886
Author: Michael S
Date: Tue, 27 Oct 2026 20:51
80 lines
3682 bytes
On Tue, 27 Oct 2026 22:05:06 +0200
Michael S <already5chosen@yahoo.com> wrote:

> On Tue, 27 Oct 2026 21:43:42 +0200
> Michael S <already5chosen@yahoo.com> wrote:
> 
> > On Tue, 27 Oct 2026 18:40:52 GMT
> > scott@slp53.sl.home (Scott Lurndal) wrote:
> >   
> > > "Steven G. Kargl" <sgk@REMOVEtroutmask.apl.washington.edu>
> > > writes:    
> > > >On Tue, 27 Oct 2026 11:53:55 +0100, fir wrote:
> > > >      
> > > >> if ai generates me some functions it puts everywhere this f at
> > > >> the and yet it add zeros so instead of .1 i got 0.1f
> > > >> 
> > > >> and i obviously dont like it
> > > >> 
> > > >> i write hvever some codes when i need speed so the question is
> > > >> may it give some difference?
> > > >> 
> > > >> i mean .1 maybe can be treated as doube constants so mabe
> > > >> occupies some more memory (?) or uses some casting in
> > > >> coplutations (?)
> > > >> 
> > > >> 
> > > >> i doubt it probably it makes difference but im strictly not
> > > >> sure 
> > > >
> > > >The leading zero in 0.1 or 0.1f is irrelevant, but (to me) makes 
> > > >code easier to read.  The difference between 0.1 and 0.1f with
> > > >their binary representations is a another matter.
> > > >
> > > >#include <stdio.h>
> > > >
> > > >int
> > > >main(void)
> > > >{
> > > >   double d;
> > > >   d = 0.1f;
> > > >   printf("%.13a\n", d);
> > > >   d = 0.1;
> > > >   printf("%.13a\n", d);
> > > >   return (0);
> > > >}
> > > >
> > > >% cc -o z t.c && ./z
> > > >0x1.99999a0000000p-4
> > > >0x1.999999999999ap-4
> > > >
> > > >The real number is 0.1 is not exactly representable in a binary
> > > >floating point format.  See
> > > >
> > > >https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html
> > > >    
> > > 
> > > I ordered a couple of blu-rays from amazon last week, and the
> > > confirmation email had the following for the total price:
> > > 
> > >    Total
> > >    75.71000000000001 USD
> > > 
> > > Appears they may be using FP instead of integer fixed point
> > > arithmetic for pricing.    
> > 
> > At least, unlike favorite AI of fir, Amazon was not using
> > single-precision.
> > 
> > 
> >   
> 
> BTW, 75.71000000000001 looks like 67 * 1.13 in IEEE binary64, but
> rounded up rather than to nearest.
> 

Or 67 + 67 * 0.13 rounded to nearest.



Re: .5 against 0.5f
#887
Author: fir
Date: Tue, 27 Oct 2026 20:57
283 lines
10422 bytes
fir pisze:
> Steven G. Kargl pisze:
>> On Tue, 27 Oct 2026 18:50:09 +0100, fir wrote:
>>
>>> Steven G. Kargl pisze:
>>>> On Tue, 27 Oct 2026 11:53:55 +0100, fir wrote:
>>>>
>>>>> if ai generates me some functions it puts everywhere this f at the and
>>>>> yet it add zeros so instead of .1 i got 0.1f
>>>>>
>>>>> and i obviously dont like it
>>>>>
>>>>> i write hvever some codes when i need speed so the question is may it
>>>>> give some difference?
>>>>>
>>>>> i mean .1 maybe can be treated as doube constants so mabe occupies
>>>>> some more memory (?) or uses some casting in coplutations (?)
>>>>>
>>>>>
>>>>> i doubt it probably it makes difference but im strictly not sure
>>>>
>>>> The leading zero in 0.1 or 0.1f is irrelevant, but (to me) makes code
>>>> easier to read.  The difference between 0.1 and 0.1f with their binary
>>>> representations is a another matter.
>>>>
>>>> #include <stdio.h>
>>>>
>>>> int main(void)
>>>> {
>>>>      double d;
>>>>      d = 0.1f; printf("%.13a\n", d);
>>>>      d = 0.1; printf("%.13a\n", d);
>>>>      return (0);
>>>> }
>>>>
>>>> % cc -o z t.c && ./z 0x1.99999a0000000p-4 0x1.999999999999ap-4
>>>>
>>>> The real number is 0.1 is not exactly representable in a binary
>>>> floating point format.  See
>>>>
>>>> https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html
>>>>
>>     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>>     Here is your answer.
>>
>>> but the question is: can using .1 instead of 0.1f make me any harm in
>>> code? like things get slower in runtime? (assuming i use floats in code
>>> not doubles, and the code is a bit time critical like rasterisation goes
>>> on floats)  why the ai so maniacally puts that f?
>>
>> Without seeing code and not knowing whether you are concerned with
>> the propagation of floating point errors, the only answer that one can
>> give for your first two questions is "yes, no, maybe".
>>
>> AI is likely appending the f because you instructed AI to use a
>> float type.  Why not ask AI why it appends the f?
>>
> it says: i add f that the number would be float type instead of double
> 
> 
> float x=a*1.5;
> 
> it also says in such above case the multiplication would be in double 
> then converted to float - bout for me its hard to belive
> 
> (i some cases ai not quite tells the truth and i cant easily validate it)
> 
> it also not gives stright answe if pushed - it says more liek id depends 
> on flags, compiler may or may
> 
> so this is no good answer
> 
> (and i asume there may be soem simple answer here i dont know
> (and i suspect its rather - no it will generate float no silly conversions
> 
> if no that would be bad)
> 
> 
ai is besides obviously great - it just drawed me even a small cosmonaut 
right now

https://www.youtube.com/watch?v=aZ1F4soMRHE


its code is not even long




static float3 astronaut_v[512];
static int astronaut_tri[1024][3];
static unsigned astronaut_color[1024];
static int astronaut_vertex_count=0;
static int astronaut_triangle_count=0;
static int astronaut_initialized=0;

void AstronautVertex(float x,float y,float z)
{
	if(astronaut_vertex_count>=512) return;
	astronaut_v[astronaut_vertex_count++]=f3(x,y,z);
}

void AstronautTriangle(int a,int b,int c,unsigned color)
{
	if(astronaut_triangle_count>=1024) return;
	int i=astronaut_triangle_count++;
	astronaut_tri[i][0]=a;
	astronaut_tri[i][1]=b;
	astronaut_tri[i][2]=c;
	astronaut_color[i]=color;
}

void AstronautQuad(int a,int b,int c,int d,unsigned color)
{
	AstronautTriangle(a,b,c,color);
	AstronautTriangle(a,c,d,color);
}

void AstronautBox(float x,float y,float z,float sx,float sy,float 
sz,unsigned color)
{
	int b=astronaut_vertex_count;
	if(b+8>512 || astronaut_triangle_count+12>1024) return;

	AstronautVertex(x-sx,y-sy,z-sz);
	AstronautVertex(x+sx,y-sy,z-sz);
	AstronautVertex(x+sx,y+sy,z-sz);
	AstronautVertex(x-sx,y+sy,z-sz);
	AstronautVertex(x-sx,y-sy,z+sz);
	AstronautVertex(x+sx,y-sy,z+sz);
	AstronautVertex(x+sx,y+sy,z+sz);
	AstronautVertex(x-sx,y+sy,z+sz);

	AstronautQuad(b,b+3,b+2,b+1,color);
	AstronautQuad(b+4,b+5,b+6,b+7,color);
	AstronautQuad(b,b+1,b+5,b+4,color);
	AstronautQuad(b+1,b+2,b+6,b+5,color);
	AstronautQuad(b+2,b+3,b+7,b+6,color);
	AstronautQuad(b+3,b,b+4,b+7,color);
}

void AstronautBuild(void)
{
	if(astronaut_initialized) return;
	astronaut_vertex_count=0;
	astronaut_triangle_count=0;

	// Buty.
	AstronautBox(-4,24,1,3.5f,3,5.5f,0x343b43);
	AstronautBox( 4,24,1,3.5f,3,5.5f,0x343b43);
	AstronautBox(-4,22.5f,3,3.2f,1.1f,3.5f,0x68747d);
	AstronautBox( 4,22.5f,3,3.2f,1.1f,3.5f,0x68747d);

	// Nogi i kolana.
	AstronautBox(-4,17,0,2.8f,5.5f,3.5f,0xd5d8d6);
	AstronautBox( 4,17,0,2.8f,5.5f,3.5f,0xd5d8d6);
	AstronautBox(-4,11,0,3,2.3f,3.8f,0x626c74);
	AstronautBox( 4,11,0,3,2.3f,3.8f,0x626c74);
	AstronautBox(-4,7,0,2.8f,3.8f,3.3f,0xe1e2dc);
	AstronautBox( 4,7,0,2.8f,3.8f,3.3f,0xe1e2dc);
	AstronautBox(-4,17,3.5f,2.4f,0.9f,0.7f,0xf28a32);
	AstronautBox( 4,17,3.5f,2.4f,0.9f,0.7f,0xf28a32);

	// Tułów i kombinezon.
	AstronautBox(0,-1,0,7,9,4.5f,0xd9dcd8);
	AstronautBox(0,-1,4.2f,5.5f,6.5f,0.8f,0xb5c0c2);
	AstronautBox(0,-1,5,3.7f,3.5f,0.5f,0x303b43);

	// Panel sterowania na piersi.
	AstronautBox(0,-3,5.65f,2.8f,2.6f,0.35f,0x505c64);
	AstronautBox(-1,-3.5f,6.05f,0.65f,0.65f,0.15f,0xf28a32);
	AstronautBox( 1,-3.5f,6.05f,0.65f,0.65f,0.15f,0x5a9bb5);
	AstronautBox(-1,-1.9f,6.05f,0.4f,0.35f,0.15f,0xd8d8d0);
	AstronautBox( 1,-1.9f,6.05f,0.4f,0.35f,0.15f,0xd8d8d0);

	// Pas i boczne kieszenie.
	AstronautBox(0,5,0,7.2f,1.3f,4.8f,0x424b52);
	AstronautBox(-6,2,0,1.5f,2.2f,3.5f,0x778087);
	AstronautBox( 6,2,0,1.5f,2.2f,3.5f,0x778087);
	AstronautBox(-6,2,3.4f,0.8f,1.4f,0.5f,0xf28a32);
	AstronautBox( 6,2,3.4f,0.8f,1.4f,0.5f,0xf28a32);

	// Plecak za tułowiem.
	AstronautBox(0,-1,-5.5f,5.5f,7.5f,2.5f,0x69747b);
	AstronautBox(0,-1,-8,4.2f,5.5f,0.5f,0x343e47);
	AstronautBox(-3,-1,-8.6f,0.8f,4,0.4f,0xf28a32);
	AstronautBox( 3,-1,-8.6f,0.8f,4,0.4f,0xf28a32);
	AstronautBox(0,-6,-8.3f,2.5f,1,0.4f,0xbac2c3);
	AstronautBox(0, 4,-8.3f,2.5f,1,0.4f,0xbac2c3);

	// Ramiona.
	AstronautBox(-9,-3,0,3,5,3.5f,0xd8dbd7);
	AstronautBox( 9,-3,0,3,5,3.5f,0xd8dbd7);
	AstronautBox(-9,-6,0,3.1f,1,3.8f,0xf28a32);
	AstronautBox( 9,-6,0,3.1f,1,3.8f,0xf28a32);
	AstronautBox(-11,-1,0,2.1f,4,3,0xd8dbd7);
	AstronautBox( 11,-1,0,2.1f,4,3,0xd8dbd7);

	// Rękawice.
	AstronautBox(-12,3,0,2.2f,2.5f,2.7f,0x505b64);
	AstronautBox( 12,3,0,2.2f,2.5f,2.7f,0x505b64);
	AstronautBox(-12,3,2.1f,1.6f,1.7f,0.7f,0x7d878d);
	AstronautBox( 12,3,2.1f,1.6f,1.7f,0.7f,0x7d878d);

	// Szyja i pierścień hełmu.
	AstronautBox(0,-10,0,4,1.5f,4,0x6a747b);
	AstronautBox(0,-11,0,5.6f,1.2f,5.6f,0x858e94);
	AstronautBox(0,-11,0,4.7f,0.7f,4.7f,0xf28a32);

	// Kask.
	AstronautBox(0,-17,0,6.5f,6,5.5f,0xdde0dc);
	AstronautBox(0,-17,4.5f,5.3f,4.2f,1.5f,0x303b43);
	AstronautBox(0,-17,5.8f,4.4f,3.2f,0.5f,0x111d2a);
	AstronautBox(0,-17,6.1f,3.7f,2.5f,0.3f,0x16435c);
	// Boki kasku i mocowania.
	AstronautBox(-6.6f,-17,0,1.2f,2.8f,2.8f,0x69757d);
	AstronautBox( 6.6f,-17,0,1.2f,2.8f,2.8f,0x69757d);
	AstronautBox(-7.2f,-17,0,0.7f,2,2,0xf28a32);
	AstronautBox( 7.2f,-17,0,0.7f,2,2,0xf28a32);

	// Detale skafandra.
	AstronautBox(-6,7,3,0.8f,1.4f,0.6f,0xf28a32);
	AstronautBox( 6,7,3,0.8f,1.4f,0.6f,0xf28a32);
	AstronautBox(-2,10,3,0.7f,1.5f,0.6f,0x505b64);
	AstronautBox( 2,10,3,0.7f,1.5f,0.6f,0x505b64);
	AstronautBox(0,7,3,1.3f,0.6f,0.6f,0xf28a32);

	astronaut_initialized=1;
}

void DrawAstronaut3DPos(Position *p,float scale)
{
	AstronautBuild();

	for(int i=0;i<astronaut_triangle_count;i++)
	{
		float3 va=astronaut_v[astronaut_tri[i][0]];
		float3 vb=astronaut_v[astronaut_tri[i][1]];
		float3 vc=astronaut_v[astronaut_tri[i][2]];

		float3 
a=f3((*p).pos.x+(va.x*(*p).right.x+va.y*(*p).down.x+va.z*(*p).dir.x)*scale,
		 
(*p).pos.y+(va.x*(*p).right.y+va.y*(*p).down.y+va.z*(*p).dir.y)*scale,
		 
(*p).pos.z+(va.x*(*p).right.z+va.y*(*p).down.z+va.z*(*p).dir.z)*scale);

		float3 
b=f3((*p).pos.x+(vb.x*(*p).right.x+vb.y*(*p).down.x+vb.z*(*p).dir.x)*scale,
		 
(*p).pos.y+(vb.x*(*p).right.y+vb.y*(*p).down.y+vb.z*(*p).dir.y)*scale,
		 
(*p).pos.z+(vb.x*(*p).right.z+vb.y*(*p).down.z+vb.z*(*p).dir.z)*scale);

		float3 
c=f3((*p).pos.x+(vc.x*(*p).right.x+vc.y*(*p).down.x+vc.z*(*p).dir.x)*scale,
		 
(*p).pos.y+(vc.x*(*p).right.y+vc.y*(*p).down.y+vc.z*(*p).dir.y)*scale,
		 
(*p).pos.z+(vc.x*(*p).right.z+vc.y*(*p).down.z+vc.z*(*p).dir.z)*scale);

		FillDepthTriangle3D(a,b,c,astronaut_color[i]);
	}
}

void DrawAstronaut(void)
{
	static Position p;
	static int initialized=0;

	if(!initialized)
	{
		p.pos=f3(100,0,1700);
		p.right=f3(1,0,0);
		p.down=f3(0,1,0);
		p.dir=f3(0,0,1);
		initialized=1;
	}

	RollIt(&p,0.0005f);
	DrawAstronaut3DPos(&p,1.0f);
}
Re: .5 against 0.5f
#888
Author: bartc
Date: Tue, 27 Oct 2026 21:03
51 lines
3321 bytes
On 27/10/2026 20:05, Kaz Kylheku wrote:
> On 2026-10-27, Scott Lurndal <scott@slp53.sl.home> wrote:
>> I ordered a couple of blu-rays from amazon last week, and the
>> confirmation email had the following for the total price:
>>
>>     Total
>>     75.71000000000001 USD
>>
>> Appears they may be using FP instead of integer fixed point arithmetic
>> for pricing.
> 
> That reminds of a joke I have in the TXR Lisp fortune module,
> intended for displaying a random quip at REPL startup.
> 
> Oh, look, I got it after just a couple of tries:
> 
> This is the TXR Lisp interactive listener of TXR 302.
> Quit with :quit or Ctrl-D on an empty line. Ctrl-X ? for cheatsheet.
> 1> (quip)
> "Coding around Unicode grapheme clusters is a character-building exercise."
> 2> (quip)
> "defmicro: error: expansion is larger than original form: switch to defmacro."
> 3> (prinl (quip))
> "This could be the year of the TXR desktop; I can feel it!"
> "This could be the year of the TXR desktop; I can feel it!"
> 4> (put-line (quip))
> TXR kind of supports IEEE 754.00000000000003 floating-point.
> t
> 
> :)
> 
> FP is fine for pricing: look at how ridiculously close to 75.71
> the above approximation is. You just have to make sure never to
> let enough error accumulate so that an intermediate value
> is suddenly closer to the wrong penny value than the right one.
> (Actually you don't even want to get anywhere near that level
> of error.)

I've used floats for pricing, I think even 32-bit ones. It should work 
fine within certain levels of magnitude - you want a few spare bits of 
precision beyond individual cents.

(To clarify, 32 bits may have been used to store prices in a stock file 
for example, so typical magnitudes would have been small, but 
calculations and totals would have used 64 bits.)

But apart from doing the rounding right as you suggest, the display 
should be only showing 2 decimals when displaying dollars, not 14. That 
example is very sloppy.

Re: .5 against 0.5f
#889
Author: Chris M. Thomasson
Date: Tue, 27 Oct 2026 21:18
92 lines
4561 bytes
On 10/27/2026 1:57 PM, fir wrote:
> fir pisze:
>> Steven G. Kargl pisze:
>>> On Tue, 27 Oct 2026 18:50:09 +0100, fir wrote:
>>>
>>>> Steven G. Kargl pisze:
>>>>> On Tue, 27 Oct 2026 11:53:55 +0100, fir wrote:
>>>>>
>>>>>> if ai generates me some functions it puts everywhere this f at the 
>>>>>> and
>>>>>> yet it add zeros so instead of .1 i got 0.1f
>>>>>>
>>>>>> and i obviously dont like it
>>>>>>
>>>>>> i write hvever some codes when i need speed so the question is may it
>>>>>> give some difference?
>>>>>>
>>>>>> i mean .1 maybe can be treated as doube constants so mabe occupies
>>>>>> some more memory (?) or uses some casting in coplutations (?)
>>>>>>
>>>>>>
>>>>>> i doubt it probably it makes difference but im strictly not sure
>>>>>
>>>>> The leading zero in 0.1 or 0.1f is irrelevant, but (to me) makes code
>>>>> easier to read.  The difference between 0.1 and 0.1f with their binary
>>>>> representations is a another matter.
>>>>>
>>>>> #include <stdio.h>
>>>>>
>>>>> int main(void)
>>>>> {
>>>>>      double d;
>>>>>      d = 0.1f; printf("%.13a\n", d);
>>>>>      d = 0.1; printf("%.13a\n", d);
>>>>>      return (0);
>>>>> }
>>>>>
>>>>> % cc -o z t.c && ./z 0x1.99999a0000000p-4 0x1.999999999999ap-4
>>>>>
>>>>> The real number is 0.1 is not exactly representable in a binary
>>>>> floating point format.  See
>>>>>
>>>>> https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html
>>>>>
>>>     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>>>     Here is your answer.
>>>
>>>> but the question is: can using .1 instead of 0.1f make me any harm in
>>>> code? like things get slower in runtime? (assuming i use floats in code
>>>> not doubles, and the code is a bit time critical like rasterisation 
>>>> goes
>>>> on floats)  why the ai so maniacally puts that f?
>>>
>>> Without seeing code and not knowing whether you are concerned with
>>> the propagation of floating point errors, the only answer that one can
>>> give for your first two questions is "yes, no, maybe".
>>>
>>> AI is likely appending the f because you instructed AI to use a
>>> float type.  Why not ask AI why it appends the f?
>>>
>> it says: i add f that the number would be float type instead of double
>>
>>
>> float x=a*1.5;
>>
>> it also says in such above case the multiplication would be in double 
>> then converted to float - bout for me its hard to belive
>>
>> (i some cases ai not quite tells the truth and i cant easily validate it)
>>
>> it also not gives stright answe if pushed - it says more liek id 
>> depends on flags, compiler may or may
>>
>> so this is no good answer
>>
>> (and i asume there may be soem simple answer here i dont know
>> (and i suspect its rather - no it will generate float no silly 
>> conversions
>>
>> if no that would be bad)
>>
>>
> ai is besides obviously great - it just drawed me even a small cosmonaut 
> right now
> 
> https://www.youtube.com/watch?v=aZ1F4soMRHE
> 
> 
> its code is not even long
Let me ponder a guess... You have no idea how/why it works?

[...]
Re: .5 against 0.5f
#892
Author: James Kuyper
Date: Tue, 27 Oct 2026 21:43
63 lines
4384 bytes
On 2026-10-27 13:45, Steven G. Kargl wrote:
> On Tue, 27 Oct 2026 11:53:55 +0100, fir wrote:
> 
>> if ai generates me some functions it puts everywhere this f at the and
>> yet it add zeros so instead of .1 i got 0.1f
>>
>> and i obviously dont like it
>>
>> i write hvever some codes when i need speed so the question is may it
>> give some difference?
>>
>> i mean .1 maybe can be treated as doube constants so mabe occupies some
>> more memory (?) or uses some casting in coplutations (?)
>>
>>
>> i doubt it probably it makes difference but im strictly not sure
> 
> The leading zero in 0.1 or 0.1f is irrelevant, but (to me) makes 
> code easier to read.  The difference between 0.1 and 0.1f with
> their binary representations is a another matter.
The number 0.1 cannot be represented exactly in binary.

The C constant "0.1" implicitly has a double value. It has "either the
nearest representable value" to exactly 0.1, "or the larger or smaller
representable value immediately adjacent to the nearest representable
value, chosen in an implementation-defined
manner." (6.5.4.3p4). Since it's double precision constant,
"representable" means "representable as a double precision number".

0.1f, on the other hand, is explicitly a float value. It follows the
same rules, but with "representable" meaning "can be represented as a
float".

0.1 and 0.1f will therefore not be the same. If you convert 0.1f to
double precision, it will convert the floating point value actually
stored to double precision, not the real value it represents. "if the
value being converted can be represented exactly in the new type, it is
unchanged." (6.2.4p4) Any float value is normally representable exactly
as a double, simply by setting all of the bits that are not stored in
float format to 0 in double format. Those bits will therefore not have
the same value they would have in "0.1".

If you convert 0.1 to float, y, "... the value being converted is in the
range of values that can be represented but cannot be represented
exactly," so "the result is either the nearest higher or nearest lower
representable value, chosen in an implementation-defined manner."
(6.3.2.5p2).
Note that "nearest" is, in this case, being determined relative to the
floating point value represented by "0.1", not the mathematical value of
1/10. Also, the "implementation-defined manner" need not be the same as
the one used for determining the value of floating point constants.

So, 0.1 and 0.1f have different values, and might be even more different
after either one is converted to the other's type for comparison. The
difference is only in the last representable bits, which won't matter
for most practical purposes, but will matter if you're comparing for
exact equality.

You should use 0.1 when the value will be stored in a double or would
otherwise immediately get converted to double when used (which is often
the case). You should use 0.1f to initialize a float variable or to pass
an argument to a function whose prototype specifies that the
corresponding parameter has the type float.
Re: .5 against 0.5f
#893
Author: James Kuyper
Date: Tue, 27 Oct 2026 22:00
47 lines
3496 bytes
On 2026-10-27 15:54, Steven G. Kargl wrote:
> On Tue, 27 Oct 2026 20:15:20 +0100, fir wrote:
> 
>> Steven G. Kargl pisze:
>>> On Tue, 27 Oct 2026 18:50:09 +0100, fir wrote:
>>>
>>>> Steven G. Kargl pisze:
>>>>> On Tue, 27 Oct 2026 11:53:55 +0100, fir wrote:
> 
> (snip)
> 
>>>> but the question is: can using .1 instead of 0.1f make me any harm in
>>>> code? like things get slower in runtime? (assuming i use floats in
>>>> code not doubles, and the code is a bit time critical like
>>>> rasterisation goes on floats)  why the ai so maniacally puts that f?
>>>
>>> Without seeing code and not knowing whether you are concerned with the
>>> propagation of floating point errors, the only answer that one can give
>>> for your first two questions is "yes, no, maybe".
>>>
>>> AI is likely appending the f because you instructed AI to use a float
>>> type.  Why not ask AI why it appends the f?
>>>
>> it says: i add f that the number would be float type instead of double
>>
>> float x=a*1.5;
>>
>> it also says in such above case the multiplication would be in double
>> then converted to float - bout for me its hard to belive

The standard requires that "The usual arithmetic conversions are
performed on the operands." (6.5.6p4).  Those conversions are described
in (6.3.2.8), and require that, in a*1.5, the value of a must be
converted to a double, and that the multiplication be carried out using
double arithmetic. However, no conversion is required for a*1.5f, and
the multiplication is carried out using float arithmetic. How the
multiplication is carried out is determined without regard to what type
the result will be stored in. This means that the value of a*1.5 will
have to be converted back to float before storing it in x, while a value
of a*1.5f has no such conversion.

> 
> I do not know where to begin to address the above.  Perhaps,
> find a copy of K&R to read.
What K&R said about the matter is far less precise, and in parts,
obsolete. in particular, float values were always automatically
converted to double for purposes of calculations.
Re: .5 against 0.5f
#894
Author: James Kuyper
Date: Tue, 27 Oct 2026 22:06
13 lines
1980 bytes
On 2026-10-27 17:43, James Kuyper wrote:
...> So, 0.1 and 0.1f have different values, and might be even more
different
> after either one is converted to the other's type for comparison. The
> difference is only in the last representable bits, which won't matter
> for most practical purposes, but will matter if you're comparing for
> exact equality.

That was a mistake. The difference involves the last representable bits
of the float value, and all of the smaller bits in the double format. As
a practical matter, if float arithmetic is adequate for your
application, it won't make much difference. However, if you need double
precision, you shouldn't be using the "f" suffix.
Re: .5 against 0.5f
#895
Author: Steven G. Kargl
Date: Tue, 27 Oct 2026 22:15
21 lines
2047 bytes
On Tue, 27 Oct 2026 18:00:47 -0400, James Kuyper wrote:

> On 2026-10-27 15:54, Steven G. Kargl wrote:

> 
>> I do not know where to begin to address the above.  Perhaps,
>> find a copy of K&R to read.
> What K&R said about the matter is far less precise, and in parts,
> obsolete. in particular, float values were always automatically
> converted to double for purposes of calculations.

Yes, I know.  I suppose I could have pointing to 
N3220.pdf (working draft of C23 I have sitting around), 
but I assumed that would have fallen on blinded
eyes.

PS: K&R is still one of my favorite books for learning
a programming language; even if it is somewhat dated.

-- 
steve
Re: .5 against 0.5f
#897
Author: Keith Thompson
Date: Tue, 27 Oct 2026 22:41
32 lines
2476 bytes
Kaz Kylheku <046-301-5902@kylheku.com> writes:
> On 2026-10-27, Scott Lurndal <scott@slp53.sl.home> wrote:
>> I ordered a couple of blu-rays from amazon last week, and the
>> confirmation email had the following for the total price:
>>
>>    Total
>>    75.71000000000001 USD

[...]

> FP is fine for pricing: look at how ridiculously close to 75.71
> the above approximation is. You just have to make sure never to
> let enough error accumulate so that an intermediate value
> is suddenly closer to the wrong penny value than the right one.

And how do you do that?

> (Actually you don't even want to get anywhere near that level
> of error.)

An arbitrarily small error can result in an ambiguity.  If you
calculate a result that should, mathematically, be very close to
75.715, it could round either to 75.71 or to 75.72.

I presume there are financial regulations that specify exactly how
these calculations are to be performed.  I have no idea what those
regulations say, but anyone writing financial code had better know
about the requirements and implement them correctly.

-- 
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
void Void(void) { Void(); } /* The recursive call of the void */
Re: .5 against 0.5f
#899
Author: Keith Thompson
Date: Tue, 27 Oct 2026 22:53
34 lines
2781 bytes
James Kuyper <jameskuyper@alumni.caltech.edu> writes:
[...]
> The C constant "0.1" implicitly has a double value. It has "either the
> nearest representable value" to exactly 0.1, "or the larger or smaller
> representable value immediately adjacent to the nearest representable
> value, chosen in an implementation-defined
> manner." (6.5.4.3p4). Since it's double precision constant,
> "representable" means "representable as a double precision number".

I think you gave the wrong subsection number, and you didn't specify
which version of the standard you're quoting from.  6.5.4.3 is
"Unary arithmetic operators" in the current standard, though it
may be different in different editions.  The wording you quoted
is from 6.4.4.3p4 in N3220 (C23).

(I'd like the C standard to adopt named subsections, as used in
the C++ standard.)

[...]

> You should use 0.1 when the value will be stored in a double or would
> otherwise immediately get converted to double when used (which is often
> the case). You should use 0.1f to initialize a float variable or to pass
> an argument to a function whose prototype specifies that the
> corresponding parameter has the type float.

Using 0.1 in a context where it will be converted to float is likely
to be harmless.  Converting 0.1 to float is likely to yield the same
value as 0.1f.  That's probably not guaranteed, but if there is a
difference it's probably insignificant.

-- 
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
void Void(void) { Void(); } /* The recursive call of the void */
Re: .5 against 0.5f
#904
Author: Lawrence D’Oliveiro
Date: Wed, 28 Oct 2026 00:49
8 lines
1492 bytes
On Tue, 27 Oct 2026 18:06:25 -0400, James Kuyper wrote:

> However, if you need double precision, you shouldn't be using the
> "f" suffix.

Is there any situation where you *should* use the “f” suffix?

I am thinking: no.
Re: .5 against 0.5f
#903
Author: Keith Thompson
Date: Wed, 28 Oct 2026 01:23
28 lines
2292 bytes
Lawrence D’Oliveiro <ldo@nz.invalid> writes:
> On Tue, 27 Oct 2026 18:06:25 -0400, James Kuyper wrote:
>> However, if you need double precision, you shouldn't be using the
>> "f" suffix.
>
> Is there any situation where you *should* use the “f” suffix?
>
> I am thinking: no.

If you're working with values of type float, the "f" suffix is more
explicit.

Logically, something like

    float f = 0.1;

implies a conversion from double to float, which could be non-trivial.
In practice, the conversion is likely to be done at compile time.
The result is *probably* the same as `float f = 0.1f;`, but I don't
think that's guaranteed.

I can't think of a case were writing 0.1f rather than 0.1 would
cause any real (ahem) problems, but there are plenty of cases where
someone might consider it stylistically better.

-- 
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
void Void(void) { Void(); } /* The recursive call of the void */
Re: .5 against 0.5f
#905
Author: James Kuyper
Date: Wed, 28 Oct 2026 01:41
18 lines
2082 bytes
On 2026-10-27 20:49, Lawrence D’Oliveiro wrote:
> On Tue, 27 Oct 2026 18:06:25 -0400, James Kuyper wrote:
> 
>> However, if you need double precision, you shouldn't be using the
>> "f" suffix.
> 
> Is there any situation where you *should* use the “f” suffix?
> 
> I am thinking: no.

I've used systems where float was significantly faster than double, I
wouldn't be surprised if someone claimed that this no longer the case on
any modern machine, but I would be surprised if they had done a
sufficiently careful search to justify being certain about that.

I've seen applications where the lower precision of float was
acceptable, and the extra speed of float was essential to meeting speed
requirements.
Re: .5 against 0.5f
#906
Author: Steven G. Kargl
Date: Wed, 28 Oct 2026 01:50
43 lines
2342 bytes
On Wed, 28 Oct 2026 00:49:19 -0000 (UTC), Lawrence D’Oliveiro wrote:

> On Tue, 27 Oct 2026 18:06:25 -0400, James Kuyper wrote:
> 
>> However, if you need double precision, you shouldn't be using the
>> "f" suffix.
> 
> Is there any situation where you *should* use the “f” suffix?
> 
> I am thinking: no.

% cat j8.c
float
foo(int n, float *x)
{
   float s = 0;
   for (int i = 0; i < n; ++i) {
      s += x[i] * 0.1;
   }
   return (s);
}

% cc -o z.s -O3 -S j8.c && grep cvts z.s 
        cvtss2sd        %xmm2, %xmm2
        cvtss2sd        %xmm0, %xmm0
        cvtsd2ss        %xmm2, %xmm0
        cvtss2sd        %xmm3, %xmm2
        cvtss2sd        %xmm0, %xmm0
        cvtsd2ss        %xmm2, %xmm0
        cvtss2sd        %xmm0, %xmm1
        cvtss2sd        %xmm0, %xmm0
        cvtsd2ss        %xmm0, %xmm0

That's a lot of useless conversion if 0.1f would have been
good enough.  Change 0.1 to 0.1f in the above code.

% cc -o z.s -O3 -S j8.c && grep cvts z.s | wc -l
       0

HTH

-- 
steve
Re: .5 against 0.5f
#907
Author: James Kuyper
Date: Wed, 28 Oct 2026 01:55
32 lines
2964 bytes
On 2026-10-27 18:53, Keith Thompson wrote:
> James Kuyper <jameskuyper@alumni.caltech.edu> writes:
> [...]
>> The C constant "0.1" implicitly has a double value. It has "either the
>> nearest representable value" to exactly 0.1, "or the larger or smaller
>> representable value immediately adjacent to the nearest representable
>> value, chosen in an implementation-defined
>> manner." (6.5.4.3p4). Since it's double precision constant,
>> "representable" means "representable as a double precision number".
> 
> I think you gave the wrong subsection number, ...
Yes, that should have been 6.4.5.3p4.

> ... and you didn't specify
> which version of the standard you're quoting from. 

The latest working draft I have access to, n3685.pdf, C202y. It refers
to C23, and to dates as late as August 2025, using the past tense.

...>> You should use 0.1 when the value will be stored in a double or would
>> otherwise immediately get converted to double when used (which is often
>> the case). You should use 0.1f to initialize a float variable or to pass
>> an argument to a function whose prototype specifies that the
>> corresponding parameter has the type float.
> 
> Using 0.1 in a context where it will be converted to float is likely
> to be harmless.  Converting 0.1 to float is likely to yield the same
> value as 0.1f.  That's probably not guaranteed, but if there is a
> difference it's probably insignificant.
Using 0.1f because you don't realize that you actually need double
precision could be problematic. This thread was started by fir - I
wouldn't rule out such a possibility.
Re: .5 against 0.5f
#908
Author: Keith Thompson
Date: Wed, 28 Oct 2026 02:02
42 lines
3091 bytes
James Kuyper <jameskuyper@alumni.caltech.edu> writes:
> On 2026-10-27 18:53, Keith Thompson wrote:
>> James Kuyper <jameskuyper@alumni.caltech.edu> writes:
>> [...]
>>> The C constant "0.1" implicitly has a double value. It has "either the
>>> nearest representable value" to exactly 0.1, "or the larger or smaller
>>> representable value immediately adjacent to the nearest representable
>>> value, chosen in an implementation-defined
>>> manner." (6.5.4.3p4). Since it's double precision constant,
>>> "representable" means "representable as a double precision number".
>> 
>> I think you gave the wrong subsection number, ...
> Yes, that should have been 6.4.5.3p4.
>
>> ... and you didn't specify
>> which version of the standard you're quoting from. 
>
> The latest working draft I have access to, n3685.pdf, C202y. It refers
> to C23, and to dates as late as August 2025, using the past tense.

The draft closest to the C23 standard is N3220.

The latest C2y draft is N3998, just released a few days ago.

https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3220.pdf
https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3998.pdf

[...]
>> Using 0.1 in a context where it will be converted to float is likely
>> to be harmless.  Converting 0.1 to float is likely to yield the same
>> value as 0.1f.  That's probably not guaranteed, but if there is a
>> difference it's probably insignificant.
>
> Using 0.1f because you don't realize that you actually need double
> precision could be problematic. This thread was started by fir - I
> wouldn't rule out such a possibility.

Sure -- but I did specify "where it will be converted to float".

-- 
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
void Void(void) { Void(); } /* The recursive call of the void */
Re: .5 against 0.5f
#917
Author: steve g
Date: Wed, 28 Oct 2026 06:11
18 lines
1917 bytes
fir <profesor.fir@gmail.com> writes:
>
>
> but the question is: can using .1 instead of 0.1f make me any harm in code?
> like things get slower in runtime? (assuming i use floats in code
> not doubles, and the code is a bit time critical like rasterisation goes on
> floats)  why the ai so maniacally puts that f?

dunno, the Gnu Libc has many options for floats/doubles. You can use a
prefix of `-' and such. check gnu libc manual on google.

> i gues the answer is NOT but maybe soem can show at least one case it could be
> worse?

12.12.10 Parsing a Template String
----------------------------------

GNU Libc --- have fun...
Re: .5 against 0.5f
#918
Author: steve g
Date: Wed, 28 Oct 2026 06:19
38 lines
2407 bytes
fir <profesor.fir@gmail.com> writes:


> float x=a*1.5;
>
> it also says in such above case the multiplication would be in double then
> converted to float - bout for me its hard to belive

you could use ratios.

> (i some cases ai not quite tells the truth and i cant easily validate it)

Hahha... TMS?

> it also not gives stright answe if pushed - it says more liek id depends on
> flags, compiler may or may
>
> so this is no good answer

Welcome to programming :)

> (and i asume there may be soem simple answer here i dont know
> (and i suspect its rather - no it will generate float no silly conversions

Unlikely.

> if no that would be bad)

Try lisp, you can use fractions, ratios, very large doubles. It is
somewhat slow with floating point usually. Ratios I like.  1/100 - that
is it.

If you want real speed with numbers I would look into fortran (actually
I would not).

 -> (numerator (/ 1 100)) => 1
 -> (denominator (/ 1 100) => 100
Re: .5 against 0.5f
#919
Author: steve g
Date: Wed, 28 Oct 2026 06:20
8 lines
1738 bytes
"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> writes:


> Oh, but the ai is his nest of books. Almost like the tommyknockers from
> Stephen King. The residents of Haven started making things that they did not
> understand at all.

Thank you!
Re: .5 against 0.5f
#920
Author: Keith Thompson
Date: Wed, 28 Oct 2026 06:21
33 lines
2536 bytes
steve g <Sgonedes1977@gmail.com> writes:
> fir <profesor.fir@gmail.com> writes:
>> but the question is: can using .1 instead of 0.1f make me any harm in code?
>> like things get slower in runtime? (assuming i use floats in code
>> not doubles, and the code is a bit time critical like rasterisation goes on
>> floats)  why the ai so maniacally puts that f?
>
> dunno, the Gnu Libc has many options for floats/doubles. You can use a
> prefix of `-' and such. check gnu libc manual on google.

fir was asking about a C language issue, nothing to do with GNU libc or
any other implementation of the C standard library.

What on Earth does "prefix of `-'" refer to?

>> i gues the answer is NOT but maybe soem can show at least one case it could be
>> worse?
>
> 12.12.10 Parsing a Template String
> ----------------------------------
>
> GNU Libc --- have fun...

That has nothing to do with the question, which was about 0.1 vs. 0.1f
in C source code.  And that question has already been discussed at some
length.

I don't want to discourage you from posting, but maybe you should
concentrate on asking questions rather than trying to answer them.

-- 
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
void Void(void) { Void(); } /* The recursive call of the void */
Re: .5 against 0.5f
#922
Author: steve g
Date: Wed, 28 Oct 2026 06:25
13 lines
1630 bytes
scott@slp53.sl.home (Scott Lurndal) writes:

> I ordered a couple of blu-rays from amazon last week, and the
> confirmation email had the following for the total price:
>
>    Total
>    75.71000000000001 USD
>
> Appears they may be using FP instead of integer fixed point arithmetic
> for pricing.

Try asking them for (ceiling 75.71000000000001)
Re: .5 against 0.5f
#924
Author: fir
Date: Wed, 28 Oct 2026 06:32
52 lines
2847 bytes
Steven G. Kargl pisze:
> On Wed, 28 Oct 2026 00:49:19 -0000 (UTC), Lawrence D’Oliveiro wrote:
> 
>> On Tue, 27 Oct 2026 18:06:25 -0400, James Kuyper wrote:
>>
>>> However, if you need double precision, you shouldn't be using the
>>> "f" suffix.
>>
>> Is there any situation where you *should* use the “f” suffix?
>>
>> I am thinking: no.
> 
> % cat j8.c
> float
> foo(int n, float *x)
> {
>     float s = 0;
>     for (int i = 0; i < n; ++i) {
>        s += x[i] * 0.1;
>     }
>     return (s);
> }
> 
> % cc -o z.s -O3 -S j8.c && grep cvts z.s
>          cvtss2sd        %xmm2, %xmm2
>          cvtss2sd        %xmm0, %xmm0
>          cvtsd2ss        %xmm2, %xmm0
>          cvtss2sd        %xmm3, %xmm2
>          cvtss2sd        %xmm0, %xmm0
>          cvtsd2ss        %xmm2, %xmm0
>          cvtss2sd        %xmm0, %xmm1
>          cvtss2sd        %xmm0, %xmm0
>          cvtsd2ss        %xmm0, %xmm0
> 
> That's a lot of useless conversion if 0.1f would have been
> good enough.  Change 0.1 to 0.1f in the above code.
> 
> % cc -o z.s -O3 -S j8.c && grep cvts z.s | wc -l
>         0
> 
> HTH
> 

if so its totally terrible, i was kinda not aware of that


i would say its wrong and stupid probably becouse in float computations 
such numbers should be floats imo in doubles it should be doubles


i should run my own test but im too exhausted
Re: .5 against 0.5f
#925
Author: fir
Date: Wed, 28 Oct 2026 06:51
64 lines
3489 bytes
fir pisze:
> Steven G. Kargl pisze:
>> On Wed, 28 Oct 2026 00:49:19 -0000 (UTC), Lawrence D’Oliveiro wrote:
>>
>>> On Tue, 27 Oct 2026 18:06:25 -0400, James Kuyper wrote:
>>>
>>>> However, if you need double precision, you shouldn't be using the
>>>> "f" suffix.
>>>
>>> Is there any situation where you *should* use the “f” suffix?
>>>
>>> I am thinking: no.
>>
>> % cat j8.c
>> float
>> foo(int n, float *x)
>> {
>>     float s = 0;
>>     for (int i = 0; i < n; ++i) {
>>        s += x[i] * 0.1;
>>     }
>>     return (s);
>> }
>>
>> % cc -o z.s -O3 -S j8.c && grep cvts z.s
>>          cvtss2sd        %xmm2, %xmm2
>>          cvtss2sd        %xmm0, %xmm0
>>          cvtsd2ss        %xmm2, %xmm0
>>          cvtss2sd        %xmm3, %xmm2
>>          cvtss2sd        %xmm0, %xmm0
>>          cvtsd2ss        %xmm2, %xmm0
>>          cvtss2sd        %xmm0, %xmm1
>>          cvtss2sd        %xmm0, %xmm0
>>          cvtsd2ss        %xmm0, %xmm0
>>
>> That's a lot of useless conversion if 0.1f would have been
>> good enough.  Change 0.1 to 0.1f in the above code.
>>
>> % cc -o z.s -O3 -S j8.c && grep cvts z.s | wc -l
>>         0
>>
>> HTH
>>
> 
> if so its totally terrible, i was kinda not aware of that
> 
> 
> i would say its wrong and stupid probably becouse in float computations 
> such numbers should be floats imo in doubles it should be doubles
> 
> 
> i should run my own test but im too exhausted
> 
maybe no wonder i was not aware of this if this is so stupid it no come 
to my mind
(should i also write 0.0f insetad of 0 BTW?)

as to optimistation there is probably a flag wjich turns it off 0 i mean
replace .1 as doube as .1 as floats when it can help to remove this 
conversions

but im not sure which one in gcc probably -ffast-math

but i not tested/talked yet
Re: .5 against 0.5f
#926
Author: fir
Date: Wed, 28 Oct 2026 06:55
72 lines
3707 bytes
fir pisze:
> fir pisze:
>> Steven G. Kargl pisze:
>>> On Wed, 28 Oct 2026 00:49:19 -0000 (UTC), Lawrence D’Oliveiro wrote:
>>>
>>>> On Tue, 27 Oct 2026 18:06:25 -0400, James Kuyper wrote:
>>>>
>>>>> However, if you need double precision, you shouldn't be using the
>>>>> "f" suffix.
>>>>
>>>> Is there any situation where you *should* use the “f” suffix?
>>>>
>>>> I am thinking: no.
>>>
>>> % cat j8.c
>>> float
>>> foo(int n, float *x)
>>> {
>>>     float s = 0;
>>>     for (int i = 0; i < n; ++i) {
>>>        s += x[i] * 0.1;
>>>     }
>>>     return (s);
>>> }
>>>
>>> % cc -o z.s -O3 -S j8.c && grep cvts z.s
>>>          cvtss2sd        %xmm2, %xmm2
>>>          cvtss2sd        %xmm0, %xmm0
>>>          cvtsd2ss        %xmm2, %xmm0
>>>          cvtss2sd        %xmm3, %xmm2
>>>          cvtss2sd        %xmm0, %xmm0
>>>          cvtsd2ss        %xmm2, %xmm0
>>>          cvtss2sd        %xmm0, %xmm1
>>>          cvtss2sd        %xmm0, %xmm0
>>>          cvtsd2ss        %xmm0, %xmm0
>>>
>>> That's a lot of useless conversion if 0.1f would have been
>>> good enough.  Change 0.1 to 0.1f in the above code.
>>>
>>> % cc -o z.s -O3 -S j8.c && grep cvts z.s | wc -l
>>>         0
>>>
>>> HTH
>>>
>>
>> if so its totally terrible, i was kinda not aware of that
>>
>>
>> i would say its wrong and stupid probably becouse in float 
>> computations such numbers should be floats imo in doubles it should be 
>> doubles
>>
>>
>> i should run my own test but im too exhausted
>>
> maybe no wonder i was not aware of this if this is so stupid it no come 
> to my mind
> (should i also write 0.0f insetad of 0 BTW?)
> 
> as to optimistation there is probably a flag wjich turns it off 0 i mean
> replace .1 as doube as .1 as floats when it can help to remove this 
> conversions
> 
> but im not sure which one in gcc probably -ffast-math
> 
> but i not tested/talked yet
ai says even fast math not enebles that but there is a flag


-fsingle-precision-constant.

Re: .5 against 0.5f
#929
Author: David Brown
Date: Wed, 28 Oct 2026 07:39
18 lines
1947 bytes
On 28/10/2026 01:49, Lawrence D’Oliveiro wrote:
> On Tue, 27 Oct 2026 18:06:25 -0400, James Kuyper wrote:
> 
>> However, if you need double precision, you shouldn't be using the
>> "f" suffix.
> 
> Is there any situation where you *should* use the “f” suffix?
> 
> I am thinking: no.

Try thinking harder.

I use the "f" suffix all the time in my code, because I do not want 
double precision.  In many situations, single precision arithmetic is at 
least twice as fast as double precision - in some situations it can be 
two orders of magnitude faster.

Re: .5 against 0.5f
#931
Author: David Brown
Date: Wed, 28 Oct 2026 07:45
32 lines
2653 bytes
On 28/10/2026 02:41, James Kuyper wrote:
> On 2026-10-27 20:49, Lawrence D’Oliveiro wrote:
>> On Tue, 27 Oct 2026 18:06:25 -0400, James Kuyper wrote:
>>
>>> However, if you need double precision, you shouldn't be using the
>>> "f" suffix.
>>
>> Is there any situation where you *should* use the “f” suffix?
>>
>> I am thinking: no.
> 
> I've used systems where float was significantly faster than double, I
> wouldn't be surprised if someone claimed that this no longer the case on
> any modern machine, but I would be surprised if they had done a
> sufficiently careful search to justify being certain about that.
> 

If they were certain about it, then they certainly would not have done a 
careful enough search.

> I've seen applications where the lower precision of float was
> acceptable, and the extra speed of float was essential to meeting speed
> requirements.

People use 16-bit and 8-bit floating point formats too.  I expect that 
these days, most floating point calculations executed across the world 
are 8 bit.

Once you have enough precision that your calculations are accurate 
enough for your required application, there's little point in using 
bigger formats - especially if speed is relevant.
Re: .5 against 0.5f
#934
Author: David Brown
Date: Wed, 28 Oct 2026 07:56
27 lines
2693 bytes
On 27/10/2026 23:53, Keith Thompson wrote:
> James Kuyper <jameskuyper@alumni.caltech.edu> writes:
> [...]
>> The C constant "0.1" implicitly has a double value. It has "either the
>> nearest representable value" to exactly 0.1, "or the larger or smaller
>> representable value immediately adjacent to the nearest representable
>> value, chosen in an implementation-defined
>> manner." (6.5.4.3p4). Since it's double precision constant,
>> "representable" means "representable as a double precision number".
> 
> I think you gave the wrong subsection number, and you didn't specify
> which version of the standard you're quoting from.  6.5.4.3 is
> "Unary arithmetic operators" in the current standard, though it
> may be different in different editions.  The wording you quoted
> is from 6.4.4.3p4 in N3220 (C23).
> 
> (I'd like the C standard to adopt named subsections, as used in
> the C++ standard.)
> 

Section numbering in the C standards was fine until C23 - from C90 to 
C17, almost all changes added new numbered sections without changing the 
existing ones.  But C23 had too many changes, and some things were 
renumbered.  So I /was/ happy with numbered, rather than named, 
sections.  Going forward, however, I agree with you - named subsections 
seem the best choice for consistent references.
Re: .5 against 0.5f
#944
Author: Tim Rentsch
Date: Wed, 28 Oct 2026 13:54
45 lines
3300 bytes
James Kuyper <jameskuyper@alumni.caltech.edu> writes:

> On 2026-10-27 15:54, Steven G. Kargl wrote:
>> On Tue, 27 Oct 2026 20:15:20 +0100, fir wrote:
>>> Steven G. Kargl pisze:
>>>> On Tue, 27 Oct 2026 18:50:09 +0100, fir wrote:
>>>>> Steven G. Kargl pisze:
>>>>>> On Tue, 27 Oct 2026 11:53:55 +0100, fir wrote:
>>
>> (snip)
>>
>>>>> but the question is:  can using .1 instead of 0.1f make me any
>>>>> harm in code?  like things get slower in runtime?  (assuming i
>>>>> use floats in code not doubles, and the code is a bit time
>>>>> critical like rasterisation goes on floats) why the ai so
>>>>> maniacally puts that f?
>>>>
>>>> Without seeing code and not knowing whether you are concerned
>>>> with the propagation of floating point errors, the only answer
>>>> that one can give for your first two questions is "yes, no,
>>>> maybe".
>>>>
>>>> AI is likely appending the f because you instructed AI to use a
>>>> float type.  Why not ask AI why it appends the f?
>>>
>>> it says:  i add f that the number would be float type instead of
>>> double
>>>
>>> float x=a*1.5;
>>>
>>> it also says in such above case the multiplication would be in
>>> double then converted to float - bout for me its hard to belive
>
> The standard requires that "The usual arithmetic conversions are
> performed on the operands."  (6.5.6p4).  Those conversions are
> described in (6.3.2.8), and require that, in a*1.5, the value of a
> must be converted to a double, and that the multiplication be
> carried out using double arithmetic.  However, no conversion is
> required for a*1.5f, and the multiplication is carried out using
> float arithmetic.  [...]

Maybe.  IIANM the C standard allows floating operations to be
carried out in greater precision than the nominal type of the
expression, and thus a*1.5f might very well be carried out using,
e.g., the same operations as would be used by double.
Re: .5 against 0.5f
#945
Author: tTh
Date: Wed, 28 Oct 2026 14:08
17 lines
1843 bytes
On 10/28/26 01:49, Lawrence D’Oliveiro wrote:
> On Tue, 27 Oct 2026 18:06:25 -0400, James Kuyper wrote:
> 
>> However, if you need double precision, you shouldn't be using the
>> "f" suffix.
> 
> Is there any situation where you *should* use the “f” suffix?
> 
> I am thinking: no.

    Explicit is better than implicit ?

-- 
**                                                            **
*                      tTh des Bourtoulots                     *
*                  http://maison.tth.netlib.re/                *
**                                                            **
Re: .5 against 0.5f
#947
Author: Tim Rentsch
Date: Wed, 28 Oct 2026 14:49
19 lines
1934 bytes
tTh <tth@none.invalid> writes:

> On 10/28/26 01:49, Lawrence D?Oliveiro wrote:
>
>> On Tue, 27 Oct 2026 18:06:25 -0400, James Kuyper wrote:
>>
>>> However, if you need double precision, you shouldn't be using the
>>> "f" suffix.
>>
>> Is there any situation where you *should* use the ?f?  suffix?
>>
>> I am thinking:  no.
>
>    Explicit is better than implicit ?

Not always, but in this case there is no "implicit" way.  If a
floating-point constant has an "f" suffix it's of type float, and
if it doesn't it's of type double.  Having a suffix necessarily
changes the meaning.
Re: .5 against 0.5f
#951
Author: Tim Rentsch
Date: Wed, 28 Oct 2026 15:01
39 lines
2909 bytes
James Kuyper <jameskuyper@alumni.caltech.edu> writes:

> On 2026-10-27 13:45, Steven G. Kargl wrote:
>
>> On Tue, 27 Oct 2026 11:53:55 +0100, fir wrote:
>>
>>> if ai generates me some functions it puts everywhere this f at the
>>> and yet it add zeros so instead of .1 i got 0.1f
>>>
>>> and i obviously dont like it
>>>
>>> i write hvever some codes when i need speed so the question is may
>>> it give some difference?
>>>
>>> i mean .1 maybe can be treated as doube constants so mabe occupies
>>> some more memory (?) or uses some casting in coplutations (?)
>>>
>>> i doubt it probably it makes difference but im strictly not sure
>>
>> The leading zero in 0.1 or 0.1f is irrelevant, but (to me) makes
>> code easier to read.  The difference between 0.1 and 0.1f with
>> their binary representations is a another matter.
>
> The number 0.1 cannot be represented exactly in binary.
>
> The C constant "0.1" implicitly has a double value.  It has "either
> the nearest representable value" to exactly 0.1, "or the larger or
> smaller representable value immediately adjacent to the nearest
> representable value, chosen in an implementation-defined manner."
> (6.5.4.3p4).  Since it's double precision constant, "representable"
> means "representable as a double precision number".
>
> 0.1f, on the other hand, is explicitly a float value.  It follows
> the same rules, but with "representable" meaning "can be represented
> as a float".

Yes, except implementations are allowed to represent floating-point
constants using a greater range and precision than the nominal type
would imply.  So 0.1 and 0.1f could have the same value.
Re: .5 against 0.5f
#952
Author: Janis Papanagnou
Date: Wed, 28 Oct 2026 15:38
40 lines
2851 bytes
On 2026-10-28 02:23, Keith Thompson wrote:
> Lawrence D’Oliveiro <ldo@nz.invalid> writes:
>> On Tue, 27 Oct 2026 18:06:25 -0400, James Kuyper wrote:
>>> However, if you need double precision, you shouldn't be using the
>>> "f" suffix.
>>
>> Is there any situation where you *should* use the “f” suffix?
>>
>> I am thinking: no.
> 
> If you're working with values of type float, the "f" suffix is more
> explicit.
> 
> Logically, something like
> 
>      float f = 0.1;
> 
> implies a conversion from double to float, which could be non-trivial.

I think "logically" is a misleading word here.

The thought of something "implicit" going on here is a thought that
might stem from (knowing) the inherent mechanisms and quirks of the
C-language not necessarily what one would logically expect.

My expectation (for sensibly defined programming languages) would be
that literals for two different "real numbers" types are generic WRT
those types; they should be usable [in "C"] without loss (or kludges)
with 'float' and 'double'.

> In practice, the conversion is likely to be done at compile time.
> The result is *probably* the same as `float f = 0.1f;`, but I don't
> think that's guaranteed.
> 
> I can't think of a case were writing 0.1f rather than 0.1 would
> cause any real (ahem) problems, but there are plenty of cases where
> someone might consider it stylistically better.

Janis
Re: .5 against 0.5f
#955
Author: Steven G. Kargl
Date: Wed, 28 Oct 2026 16:22
23 lines
2035 bytes
On Wed, 28 Oct 2026 07:51:13 +0100, fir wrote:

> (should i also write 0.0f insetad of 0 BTW?)

A lot of context removed.  No.  IMO, if you have
a numerical constant that can be written as an
integer and that integer is less than 2^P
where P is the precision of the floating point
type of interest (here, 2^P means 2 raised to
the Pth power), then simply write the numerical
constant as an integer.  It's easier to read.

float foo(float a) {
  float x = 25 * a;
  return (x);
}

A compiler ought to convert 25 in the above to
25.f as 25 is exactly representable (at least in
IEEE-754 binary32 format) in float.  

-- 
steve
Re: .5 against 0.5f
#956
Author: Scott Lurndal
Date: Wed, 28 Oct 2026 16:23
34 lines
2275 bytes
Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
>Kaz Kylheku <046-301-5902@kylheku.com> writes:
>> On 2026-10-27, Scott Lurndal <scott@slp53.sl.home> wrote:
>>> I ordered a couple of blu-rays from amazon last week, and the
>>> confirmation email had the following for the total price:
>>>
>>>    Total
>>>    75.71000000000001 USD
>
>[...]
>
>> FP is fine for pricing: look at how ridiculously close to 75.71
>> the above approximation is. You just have to make sure never to
>> let enough error accumulate so that an intermediate value
>> is suddenly closer to the wrong penny value than the right one.
>
>And how do you do that?
>
>> (Actually you don't even want to get anywhere near that level
>> of error.)
>
>An arbitrarily small error can result in an ambiguity.  If you
>calculate a result that should, mathematically, be very close to
>75.715, it could round either to 75.71 or to 75.72.
>
>I presume there are financial regulations that specify exactly how
>these calculations are to be performed.  I have no idea what those
>regulations say, but anyone writing financial code had better know
>about the requirements and implement them correctly.

There are.  And they explicitly forbid using binary floating
point representations.

Typically they use scaled fixed point 64-bit integers in modern code.
Page 1 of 4 • 158 total messages
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads