🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c
Article #889

Re: .5 against 0.5f

#889
From: 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?

[...]
Technical Details
Message-ID: <11br4f8$1t7q7$1@dont-email.me>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
References: <11bpvs7$1e6kc$2@dont-email.me> <11bqnvh$1np7s$1@dont-email.me> <11bqo8h$1o2l4$2@dont-email.me> <11bqsef$1pnhi$1@dont-email.me> <11bqt88$1q9r2$1@dont-email.me> <11br38i$1snpa$1@dont-email.me>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
From: "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>
Newsgroups: comp.lang.c
Subject: Re: .5 against 0.5f
Date: Tue, 27 Oct 2026 14:18:27 -0700
Organization: A noiseless patient Spider
Lines: 92
Message-ID: <11br4f8$1t7q7$1@dont-email.me>
References: <11bpvs7$1e6kc$2@dont-email.me> <11bqnvh$1np7s$1@dont-email.me>
 <11bqo8h$1o2l4$2@dont-email.me> <11bqsef$1pnhi$1@dont-email.me>
 <11bqt88$1q9r2$1@dont-email.me> <11br38i$1snpa$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 27 Oct 2026 21:18:33 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="2006855"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX18rb7EsiZJok8psNipXoBvE/WhqYcsnchA="; posting-host="a6c988641c9f0a5278d89ebf0389e645"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:Dh9PBP1vr35/nIwOg9RBd04ihB8= sha256:lPRU2oT6nvoM43uVdnZQQMvNj7ukXxO5WT8ZS8wKVOY=
	sha1:9wAQ/9JWt0fOVF34+CrqvDnN9AU= sha256:LQbDG27t0nbZWGod6RyT50an52X4+flLBqk0xI0xyt0=
Content-Language: en-US
In-Reply-To: <11br38i$1snpa$1@dont-email.me>