Re: Implemenation Indepdent Way to Move LSByte of Char to MSB of Int, etc

From: bd (bdonlan_at_gmail.com)
Date: 01/17/05


Date: Mon, 17 Jan 2005 15:00:53 -0500


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Eric Sosman wrote:

[...]
> Maybe there's a way to calculate (UINT_MAX + 1)/(UCHAR_MAX + 1)
> without risking zero in the numerator and/or denominator, but I
> haven't figured one out. (Note that UCHAR_MAX == ULLONG_MAX is
> permitted by the Standard.)

Since UCHAR_MAX <= UINT_MAX <= ULLONG_MAX...

#if UCHAR_MAX == ULLONG_MAX
# define UINT_UCHAR_RATIO 1
#else
# define UINT_UCHAR_RATIO \
  (((unsigned long long)UINT_MAX + 1) / \
   ((unsigned long long)UCHAR_MAX + 1))
#endif

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)

iD8DBQFB7Bl1+hz2VlChukwRAoaVAJ0Zh2DOJwBXkeNRuyG/Jd0h9dx5cACcCD6a
ybh2nBGeJaFbYrAwuhhhMhA=
=otfo
-----END PGP SIGNATURE-----



Relevant Pages

  • Re: Conflicting needs for __init__ method
    ... single integer, another Rational instance, and perhaps floats, Decimal ... And when initializing from a pair of integers---a numerator ... sure that the denominator is positive. ... like negation or raising to a positive integer power, ...
    (comp.lang.python)
  • Re: infinite product
    ... This result generalizes to products with an arbitrary number of numerator and denominator terms. ... Note that this does not always give interesting formulae, since both sides may be zero because of poles of Gamma. ... It is for this reason that it is advisable to keep x in formula. ...
    (sci.math)
  • Re: Convert decimal to fraction string
    ... You can specify the maximum denominator to use in the ... Dim GCD As Long ... Dim TopNumber As Long ... Dim Numerator As Long ...
    (microsoft.public.vb.general.discussion)
  • Re: ga10- Integers found that form the sqrt(2) or transcendental numbers.
    ... the numerator and the denominator have the same number of decimal places. ... decimal comma to construct the integers until you have no comma (the limit of the sequence). ...
    (sci.math)
  • Conflicting needs for __init__ method
    ... And when initializing from a pair of integers---a numerator ... sure that the denominator is positive. ... any of the above complications: it's easy and natural to arrange that ... possibly computationally expensive processing. ...
    (comp.lang.python)