import cinit from unix.schottelius.org
Signed-off-by: Nico Schottelius <nico@ikn.schottelius.org>
This commit is contained in:
parent
3729fc68eb
commit
423ba10303
13396 changed files with 269468 additions and 0 deletions
42
software/cinit/browse_source/cinit-0.0.4/old/cnt_digits.c
Normal file
42
software/cinit/browse_source/cinit-0.0.4/old/cnt_digits.c
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* (c) 2005 Nico Schottelius (nico-linux at schottelius.org)
|
||||
* cinit.c
|
||||
* part of cLinux/cinit
|
||||
*/
|
||||
|
||||
/* this code is stolen from gpm */
|
||||
|
||||
/* what's the english name for potenz ? */
|
||||
int x_high_y(int base, int pot_y)
|
||||
{
|
||||
int val = 1;
|
||||
|
||||
if(pot_y == 0) val = 1;
|
||||
else if(pot_y < 0) val = 0; /* ugly hack ;) */
|
||||
else while(pot_y > 0) {
|
||||
val = val * base;
|
||||
pot_y--;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
/* return characters needed to display int */
|
||||
int cnt_digits(int number)
|
||||
{
|
||||
/* 0-9 = 1 10^0 <-> (10^1)-1
|
||||
* 10 - 99 = 2 10^1 <-> (10^2)-1
|
||||
* 100 - 999 = 3 10^2 <-> (10^3)-1
|
||||
* 1000 - 9999 = 4 ... */
|
||||
|
||||
int ret = 0, num = 0;
|
||||
|
||||
/* non negative, please */
|
||||
if(number < 0) number *= -1;
|
||||
else if(number == 0) ret = 1;
|
||||
else while(number > num) {
|
||||
ret++;
|
||||
num = (x_high_y(10,ret) - 1);
|
||||
}
|
||||
|
||||
return(ret);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue