comp.lang.ada
 help / color / mirror / Atom feed
* Help with low level Ada
@ 2011-03-17 14:31 Syntax Issues
  2011-03-17 17:46 ` Shark8
  2011-03-17 17:55 ` Jeffrey Carter
  0 siblings, 2 replies; 6+ messages in thread
From: Syntax Issues @ 2011-03-17 14:31 UTC (permalink / raw)


I am translating a C math library and need help with low level
operations - setting individual bytes, and-ing data types, and bit
shifting. Below are the problems I have run in to.

---------------------------------------------------------------------------------------
Setting individual bytes
---------------------------------------------------------------------------------------
typedef float			vec_t;
typedef vec_t			vec3_t[3];
unsigned ColorNormalize (vec3_t rgb){
	unsigned	c;
	float		max;
	...
	((byte *)&c)[0] = rgb[0] * max;
	((byte *)&c)[1] = rgb[1] * max;
	((byte *)&c)[2] = rgb[2] * max;
	((byte *)&c)[3] = 255;
	return c;
}
function Normalize
	(Red_Green_Blue : in Vector_Color)
	return Integer_Color
	is
	Result  : Integer_Color := 0;
	Maximum : Float_4       := 0.0;
	begin
		...
		return
			-- ???!!??!?!? Byte(Red_Green_Blue(1) * Maximum) +
			-- ???!!??!?!? Byte(Red_Green_Blue(2) * Maximum) +
			-- ???!!??!?!? Byte(Red_Green_Blue(3) * Maximum);
	end Normalize;
---------------------------------------------------------------------------------------
And-ing Data types
---------------------------------------------------------------------------------------
float AngleMod (float angle){
	return (360.0/65536) * ((int)(angle * (65536/360.0)) & 65535);
}
function Mod_Angle
	(Angle : in Float_4)
	return Float_4
	is
	begin
		return (360.0 / 65536.0) * (Integer_4_Signed(Angle * (65536.0 /
360.0)) ---???!?!?!& 65535);
	end Mod_Angle;
---------------------------------------------------------------------------------------
Shifting
---------------------------------------------------------------------------------------
int NearestPowerOfTwo (int number, qboolean roundDown){
	int n = 1;
	if (number <= 0)
		return 1;
	while (n < number)
		n <<= 1;
	if (roundDown){
		if (n > number)
			n >>= 1;
	}
	return n;
}
---???!!?!??!?!?



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2011-03-20  3:45 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-17 14:31 Help with low level Ada Syntax Issues
2011-03-17 17:46 ` Shark8
2011-03-17 17:59   ` Jeffrey Carter
2011-03-20  3:45     ` Shark8
2011-03-17 17:55 ` Jeffrey Carter
2011-03-17 19:30   ` Syntax Issues

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox