comp.lang.ada
 help / color / mirror / Atom feed
From: Syntax Issues <syntax.issues@gmail.com>
Subject: Help with low level Ada
Date: Thu, 17 Mar 2011 07:31:47 -0700 (PDT)
Date: 2011-03-17T07:31:47-07:00	[thread overview]
Message-ID: <21e55933-291b-46a9-8659-3edf83d963b4@u3g2000vbe.googlegroups.com> (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;
}
---???!!?!??!?!?



             reply	other threads:[~2011-03-17 14:31 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-17 14:31 Syntax Issues [this message]
2011-03-17 17:46 ` Help with low level Ada 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
replies disabled

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