Topic: frexp (Was: Comparing pointer with either char(), false or (2*1*0) allowed...?)


Author: "Trevor L. Jackson, III" <fullmoon@aspi.net>
Date: 2000/08/09
Raw View
I appreciate the information, but replying upon the vagaries of the imple=
mentation is
unacceptable when dealing with esoteric issues.  The implementation's I'm=
 working with
are spotty.  I don't expect this to change soon.  Either the compilers ar=
e aging and
the vendors have decided to reduce their investment in fixing problems, o=
r they are
very new and they have bugs.

Compiler RTL bugs are a fact of life.  I believe it is worth providing th=
e hooks
necessary to bridge the inevitable gaps.

Specifics interspersed below.

Valentin Bonnard wrote:

> anTrevor L. Jackson, III wrote:
> >
> > Valentin Bonnard wrote:
> >
> > > Trevor L. Jackson, III wrote:
>
> > > > and some bit position descriptors to compose/decompose numbers in=
 a portable
> > > > way:
> > > >
> > > > int sign_bit;
> > > > int mant_bit;
> > > > int exp_bit;
> > >
> > > Why not use frexp ?
> >
> > I'd much prefer to use frexp and ldexp.  However, they are a fairly r=
estrictive
> > interface to the underlying numeric properties.  They make the fundam=
ental
> > assumption that all floating point values are numbers.  What's the ex=
ponent of
> > zero,
>
> >From the man:
>
> FREXP(3)            Linux Programmer's Manual            FREXP(3)
>
> NAME
>        frexp  -  convert  floating-point number to fractional and
>        integral components
>
> [...]
>
> RETURN VALUE
>        The frexp() function returns the normalized fraction.   If
>        the  argument  x is not zero, the normalized fraction is x
>        times a power of two, and  is  always  in  the  range  1/2
>        (inclusive) to 1 (exclusive).  If x is zero, then the nor=AD
>        malized fraction is zero and zero is stored in exp.

Other implementations return INT_MIN in order to maintain a monotonic spa=
ce of
exponents.  I.e., if X > Y >=3D 0 then frexp_arg2(X) >=3D frexp_arg2(Y), =
which makes
ldexp() consistent as well.

>
>
> > infinity or NaN?
>
> >From C99 draft:
>
>     F.9.3.4 The frexp function
>
>    [#1] - frexp(_0,exp) returns _0, and returns 0 in *exp. -
>    frexp(_oo,exp) returns _oo, and returns an unspecified value in *exp.
>    - frexp(x,exp) returns x if x is a NaN, and stores an unspecified
>    value in *exp.

I cannot trust the implementations to adhere to this.  I cannot even trus=
t that ldexp(
DBL_MIN, -10 ) will return DBL_MIN/1024.  Some implementation refuse to h=
andle denorms
much less infinities and non numbers.

Further, I don't expect to be able to trust the implementations even ten =
years after
the language requires it.  Since few programmers know or care about the i=
ssues there
is no incentive on the part of implementors to spend time on the unpopula=
r nooks and
crannies.

>
> > The only mechanism we have for composing
> > diagnostic NaNs is some kind of bit twiddling.
>
> There is the C99 nan function:
>
>   #include <math.h>
>   double nan(const char *tagp);
>
> but I don't know if it solves your problems.

It would iff (a) it were widely supported, and (b) it supported querying =
nan tags
[something I'll certainly look into].

At worst it will provide a criteria & interface I can use to implement th=
e missing
functions in as standard a way as possible -- for which I thank you.

I suppose my meta request is for the absolutely minimal set of primitives=
 by which the
RTL functions can be implemented and, more importantly, tested.


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: Valentin Bonnard <Bonnard.V@wanadoo.fr>
Date: 2000/08/09
Raw View
anTrevor L. Jackson, III wrote:
>=20
> Valentin Bonnard wrote:
>=20
> > Trevor L. Jackson, III wrote:

> > > and some bit position descriptors to compose/decompose numbers in a=
 portable
> > > way:
> > >
> > > int sign_bit;
> > > int mant_bit;
> > > int exp_bit;
> >
> > Why not use frexp ?
>=20
> I'd much prefer to use frexp and ldexp.  However, they are a fairly res=
trictive
> interface to the underlying numeric properties.  They make the fundamen=
tal
> assumption that all floating point values are numbers.  What's the expo=
nent of
> zero,

>From the man:

FREXP(3)            Linux Programmer's Manual            FREXP(3)

NAME
       frexp  -  convert  floating-point number to fractional and
       integral components

[...]

RETURN VALUE
       The frexp() function returns the normalized fraction.   If
       the  argument  x is not zero, the normalized fraction is x
       times a power of two, and  is  always  in  the  range  1/2
       (inclusive) to 1 (exclusive).  If x is zero, then the nor=AD
       malized fraction is zero and zero is stored in exp.

> infinity or NaN?

>From C99 draft:

    F.9.3.4 The frexp function
              =20
   [#1] - frexp(_0,exp) returns _0, and returns 0 in *exp. -
   frexp(_oo,exp) returns _oo, and returns an unspecified value in *exp.
   - frexp(x,exp) returns x if x is a NaN, and stores an unspecified
   value in *exp.

> The only mechanism we have for composing
> diagnostic NaNs is some kind of bit twiddling.

There is the C99 nan function:

  #include <math.h>=20
  double nan(const char *tagp);

but I don't know if it solves your problems.

--=20

Valentin Bonnard

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]