Пример #1
0
int main(int argc, char *argv[])
{
  ULONG q;

  if ((UtilityBase = (UtilType *)OpenLibrary("utility.library", 37)))
  {
    q = UDivMod32(10,2);
    Printf("%lu\n", q);

    CloseLibrary((struct Library *)UtilityBase);
  }
  return 0;
}
Пример #2
0
// Convert signed integer to a string
void LIBFUNC L_Itoa(
	REG(d0, long num),
	REG(a0, char *str),
	REG(d1, char sep))
{
	short place,val;
	BOOL first=1;

	// Zero?
	if (num==0)
	{
		*str++='0';
		*str=0;
		return;
	}

	// Negative?
	if (num<0)
	{
		num=-num;
		*str++='-';
	}

	// Go through initially to get length of number
	for (place=9;place>=0;place--)
	{
		// Anything in this place?
		if (num>=place_lookup[place]) break;
	}

	// Go through remaining decimal places
	for (;place>=0;place--)
	{
		// Get value of this place
		val=UDivMod32(num,place_lookup[place]);

		// Need a separator?
		if (first) first=0;
		else if (sep && (place==8 || place==5 || place==2)) *str++=sep;

		// Store number
		*str++=(char)('0'+val);

		// Decrement number
		num-=UMult32(val,place_lookup[place]);
	}

	// Null-terminate string
	*str=0;
}
Пример #3
0
ULONG LIBFUNC L_DivideU(
	REG(d0, unsigned long num),
	REG(d1, unsigned long div),
	REG(a0, unsigned long *rem),
	REG(a1, struct Library *lib))
{
	ULONG quotient;

#if !defined(__amigaos4__)
	quotient = UDivMod32(num, div);
#else
	quotient = (ULONG)(num / div);
#endif
	*rem = num - (div * quotient);
	return quotient;
}
Пример #4
0
// Convert long to a string base 26
void LIBFUNC L_Ito26(
	REG(d0, unsigned long num),
	REG(a0, char *str))
{
	short place,val;

	// Zero?
	if (num==0)
	{
		*str++='0';
		*str=0;
		return;
	}

	// Go through initially to get length of number
	for (place=6;place>=0;place--)
	{
		// Anything in this place?
		if (num>=place_lookup_26[place]) break;
	}

	// Go through remaining decimal places
	for (;place>=0;place--)
	{
		// Get value of this place
		val=UDivMod32(num,place_lookup_26[place]);

		// Store number
		*str++=(char)('A'+val);

		// Decrement number
		num-=UMult32(val,place_lookup_26[place]);
	}

	// Null-terminate string
	*str=0;
}
Пример #5
0
// Do division (fake float) into a string
void LIBFUNC L_DivideToString(
	REG(a0, char *string),
	REG(d0, unsigned long bytes),
	REG(d1, unsigned long div),
	REG(d2, short places),
	REG(d3, char sep))
{
	unsigned long whole;
	unsigned long remainder;

	// Zero?
	if (div==0)
	{
		string[0]='0';
		string[1]=0;
		return;
	}

	// Do division
	whole=L_DivideU(bytes,div,&remainder,UtilityBase);

	// Get whole number string
	L_ItoaU(whole,string,sep);

	// Want remainder?
	if (places>0)
	{
		char rem_buf[20],form_buf[10];
		unsigned long rem100;

		// Convert to fraction
		rem100=UDivMod32(UMult32(remainder,100),div);

		// Round up
		if (places==1) rem100+=5;

		// Rounded up to next whole number?
		if (rem100>99)
		{
			// Move to next whole number
			rem100-=100;
			++whole;

			// Get whole number string again
			L_ItoaU(whole,string,sep);
		}	

		// Build formatting string
		lsprintf(form_buf,"%%0%ldld",places+1);

		// Convert remainder to a string, chop to desired decimal places
		lsprintf(rem_buf,form_buf,rem100);
		rem_buf[places]=0;

		// Not zero?
		if (atoi(rem_buf)!=0)
		{
			char *ptr=string+strlen(string);
			lsprintf(ptr,"%lc%s",decimal_point,(IPTR)&rem_buf);
		}
	}
}