version 1.1, 1996/09/21 05:39:43 |
version 1.2, 1999/02/20 19:00:39 |
|
|
*/ |
*/ |
|
|
#include "less.h" |
#include "less.h" |
|
#include <limits.h> |
#include <signal.h> |
#include <signal.h> |
#include <setjmp.h> |
#include <setjmp.h> |
#if HAVE_TIME_H |
#if HAVE_TIME_H |
|
|
} |
} |
|
|
/* |
/* |
* Return the largest possible number that can fit in a long. |
* Return the largest possible number that can fit in a POSITION. |
*/ |
*/ |
#ifdef MAXLONG |
#ifdef QUAD_MAX |
static long |
static POSITION |
get_maxlong() |
get_maxpos() |
{ |
{ |
return (MAXLONG); |
return (QUAD_MAX); |
} |
} |
#else |
#else |
static long |
static POSITION |
get_maxlong() |
get_maxpos() |
{ |
{ |
long n, n2; |
POSITION n, n2; |
|
|
/* |
/* |
* Keep doubling n until we overflow. |
* Keep doubling n until we overflow. |
* {{ This actually only returns the largest power of two that |
* {{ This actually only returns the largest power of two that |
* can fit in a long, but percentage() doesn't really need |
* can fit in a POSITION, but percentage() doesn't really need |
* it any more accurate than that. }} |
* it any more accurate than that. }} |
*/ |
*/ |
n2 = 128; /* Hopefully no maxlong is less than 128! */ |
n2 = 128; /* Hopefully no maxpos is less than 128! */ |
do { |
do { |
n = n2; |
n = n2; |
n2 *= 2; |
n2 *= 2; |
|
|
#endif |
#endif |
|
|
/* |
/* |
* Return the ratio of two longs, as a percentage. |
* Return the ratio of two POSITIONs, as a percentage. |
*/ |
*/ |
public int |
public int |
percentage(num, den) |
percentage(num, den) |
long num, den; |
POSITION num, den; |
{ |
{ |
static long maxlong100 = 0; |
static POSITION maxpos100 = 0; |
|
|
if (maxlong100 == 0) |
if (maxpos100 == 0) |
maxlong100 = get_maxlong() / 100; |
maxpos100 = get_maxpos() / 100; |
if (num > maxlong100) |
if (num > maxpos100) |
return (num / (den/100)); |
return (num / (den/100)); |
else |
else |
return (100*num / den); |
return (100*num / den); |