Article View: comp.lang.c
Article #893Re: .5 against 0.5f
From: James Kuyper
Date: Tue, 27 Oct 2026 22:00
Date: Tue, 27 Oct 2026 22:00
47 lines
3496 bytes
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.
Technical Details
Message-ID:
<11br6ug$1u3vq$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-mailReferences:
<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> <11bqvh3$1qqsr$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: James Kuyper <jameskuyper@alumni.caltech.edu> Newsgroups: comp.lang.c Subject: Re: .5 against 0.5f Date: Tue, 27 Oct 2026 18:00:47 -0400 Organization: A noiseless patient Spider Lines: 47 Message-ID: <11br6ug$1u3vq$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> <11bqvh3$1qqsr$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Injection-Date: Tue, 27 Oct 2026 22:00:49 +0000 (UTC) Injection-Info: dont-email.me; logging-data="2035706"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18AUmJS6G5FOI90PF1F/7hESiGoooCtu/Q="; posting-host="12d93631e700fb3ab499ef75e583e1ff" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:STjX+bFf+OxZPtqmM8yf9D+oyeU= sha256:irTV3OwvdYuPwWmj2t78VU3GBp5EQ5T9shOViOZPKi4= sha1:L4bZdv+hS/NjKMkrscH8O1cuQQ4= sha256:C0dVd3G3mxBGq/Sbod050/ZfDM6Z9N6UqwlbEn0oPIs= In-Reply-To: <11bqvh3$1qqsr$1@dont-email.me> Content-Language: en-US