DEC_EVAL_METHOD
Can't seem to turn this loose.

On Tue, Sep 10, 2013 at 1:51 AM, Joel Rees <joel.r...@gmail.com> wrote:
> On Mon, Sep 9, 2013 at 4:21 PM, Dom <to...@rpdom.net> wrote:
>> On 09/09/13 07:21, Joel Rees wrote:
>> <snip code and stuff>
>>
>>>
>>> Not sure why neither man -k nor whereis can find float.h, but it compiles
>>> okay.
>>
>>
>> dom@oz:~$ locate float.h
>> /usr/lib/gcc/i486-linux-gnu/4.6/include/float.h
>> /usr/lib/gcc/i486-linux-gnu/4.7/include/float.h
>> /usr/lib/pymodules/python2.6/numpy/core/include/numpy/halffloat.h
>> /usr/lib/pymodules/python2.7/numpy/core/include/numpy/halffloat.h
>> /usr/share/pyshared/numpy/core/include/numpy/halffloat.h
>>
>> whereis looks on the PATH for a command. float.h isn't a command. It does
>> also look for manpages, but...
>
> whereis picks up stuff in /usr/include and /usr/lib, as well.
>
>> It does have a manpage:
>> http://manpages.debian.net/cgi-bin/man.cgi?query=float.h
>> but perhaps you don't have it installed. I certainly don't.
>>
>> --
>> Dom
>>
>
> I actually do have manpages-dev installed, so I can get a man page on
> fgetc, but it still doesn't give me a man page for stuff in float.h.

Now that I see that man works for the functions and macros and not for
the header name (But why wouldn't man-k pick that up?), I do a "man
pow" and notice there is a powl() function that looks like it might
work but maybe doesn't:

---------------------------
#include <stdio.h>
#include <stdlib.h>

#include <float.h>
#include <math.h>

int main( int argc, char * argv[] )
{
   double temp;
   long double ltemp;

   printf( "max double digits: %d, double exponent %d\n", DBL_DIG,
DBL_MAX_10_EXP );
   printf( "max double value: %Lf\n", (long double) DBL_MAX );

   temp = pow( 2, 2000 );
   ltemp = powl( 2, 2000 );
   printf( "2^2000 as double: %f\n", temp );
   printf( "2^2000 as long double: %Lf\n", ltemp );
   ltemp = ltemp + 1.0;
   printf( "2^2000 + 1 as long double: %Lf\n", ltemp );

   return EXIT_SUCCESS;
}
---------------------------

which prints out the value of 2^2000 okay, but fails to increment it.

Which makes sense, since we have no reason to believe long double ever
gets 2000 bits of significance, but powers of two should be accurately
stored up to the limit of the exponent.

Thus the need for GMP or MPFR  or similar libraries. (Or you can just
do it in python. ;)

    http://en.wikipedia.org/wiki/GNU_Multi-Precision_Library

and

    http://en.wikipedia.org/wiki/MPFR

I note:

    cat /usr/lib/gcc/x86_64-linux-gnu/4.7/include/float.h

a constant, DEC_EVAL_METHOD,

    #undef DEC_EVAL_METHOD
    #define DEC_EVAL_METHOD    2

might force "all operations and constants to the range and precision
of the _Decimal128 type", which might be of interest for compiling
environments which do not make long doubles longer than doubles -- a
kind of "last chance" on those systems. Unless he only needs the
constant, and doesn't need precision/accuracy, the OP is going to want
GMP or MPFR or the like, if python can't do his job.

Since I seem to be convincing myself against my better judgment that I
have time, and since I've always wanted to play with the
multiprecision stuff, I'm going to install libgmp-dev and read the
website

    http://gmplib.org/

and risk stealing the OP's opportunity for learning.

-----------------------------------------
#include <stdio.h>
#include <stdlib.h>

#include <float.h>
#include <math.h>

#include <gmp.h> /* NOT a standard header! */


int main( int argc, char * argv[] )
{
   double temp;
   long double ltemp;
   mpz_t z_result;  /* Doing it with arbitrary precision integers. */
   mpf_t f_result;  /* Doing it with arbitrary precision floats. */
   mpf_t f_2; /* Don't seem to have mpf_ui_pow_ui(). */

   printf( "max double digits: %d, double exponent %d\n", DBL_DIG,
DBL_MAX_10_EXP );
   printf( "max double value: %Lf\n", (long double) DBL_MAX );

   temp = pow( 2, 2000 );
   ltemp = powl( 2, 2000 );
   printf( "2^2000 as double: %f\n", temp );
   printf( "2^2000 as long double: %Lf\n", ltemp );
   ltemp = ltemp + 1.0;
   printf( "2^2000 + 1 as long double: %Lf\n", ltemp );

   mpz_init( z_result );
   mpz_ui_pow_ui( z_result, 2, 2000 );
   gmp_printf( "\n integer 2^2000 is \n%Zd\n", z_result );
   mpz_add_ui( z_result, z_result, 1 );
   gmp_printf( "\n integer 2^2000 + 1 is \n%Zd\n", z_result );
   mpz_clear( z_result );

   mpf_init2( f_result, 2500 ); /* A bit of extra room in the precision. */
   mpf_init_set_ui( f_2, 2 );
   mpf_pow_ui( f_result, f_2, 2000 );
   gmp_printf( "\n float 2^2000 is \n%Ff\n", f_result );
   mpf_add_ui( f_result, f_result, 1 );
   gmp_printf( "\n float 2^2000 + 1 is \n%Ff\n", f_result );

   mpf_clear( f_result );

   return EXIT_SUCCESS;
}
-----------------------------------------

Save it as float_h.c and compile it with

    cc -o float_h -lgmp -Wall float_h.c

run it with

    ./float_h

--
Joel Rees
Look around, the leaves are green,
The grass is high, it's the springtime of my life!
Yeah! FUN!


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: 
http://lists.debian.org/CAAr43iP-ZW2YSqz8hQoz-MOx9wxVqu2tJdNJBiMrqGHZAGU=u...@mail.gmail.com

Reply via email to