🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c
Article #887

Re: .5 against 0.5f

#887
From: 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);
}
Technical Details
Message-ID: <11br38i$1snpa$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>

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: fir <profesor.fir@gmail.com>
Newsgroups: comp.lang.c
Subject: Re: .5 against 0.5f
Date: Tue, 27 Oct 2026 21:57:53 +0100
Organization: A noiseless patient Spider
Lines: 283
Message-ID: <11br38i$1snpa$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>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 27 Oct 2026 20:57:55 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="1990442"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX18PInet0MRSYq3U5uE70FmFuvUdOmTX1SI="; posting-host="194c9e0146af9b1e3017ba4c59028341"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:140.0) Gecko/20100101
 Firefox/140.0 SeaMonkey/2.53.24
Cancel-Lock: sha1:fBlmcr6O7GBg5iDLCy39HqzCa/s= sha256:NOmCpywQN+in0kEwUbKA8JCST7z+3E1PHhMQCCuLbY8=
	sha1:EIa9rPKnmLDuUMyw9x3tAju1e5k= sha256:AssnwPaofOEo/S3tc0vb8FictctWHDwa2Mht9Wzgvvo=
In-Reply-To: <11bqt88$1q9r2$1@dont-email.me>