Thread: Octoproths
View Single Post
Old 2006-01-12, 16:23   #232
Greenbank
 
Greenbank's Avatar
 
Jul 2005

2×193 Posts
Default

Enhancement to octo.c

Allow numbers to be specified in scientific format (although no decimals allowed).

Following code replaces the two lines:-

mpz_set_str(kmin_gmp,argv[2],10);
mpz_set_str(kmax_gmp,argv[3],10);

Code:
        if( strchr( argv[2], 'E' ) ) {
                unsigned int a,b;
                if( sscanf( argv[2], "%uE%u", &a, &b ) == 2 ) {
                        mpz_set_ui( kmin_gmp, 10 );
                        mpz_pow_ui( kmin_gmp, kmin_gmp, b );
                        mpz_mul_ui( kmin_gmp, kmin_gmp, a );
                } else {
                        printf( "Unable to get kmin value from '%s'\n", argv[2] );
                        return(0);
                }
        } else {
          mpz_set_str(kmin_gmp,argv[2],10);
        }
        if( strchr( argv[3], 'E' ) ) {
                unsigned int a,b;
                if( sscanf( argv[3], "%uE%u", &a, &b ) == 2 ) {
                        mpz_set_ui( kmax_gmp, 10 );
                        mpz_pow_ui( kmax_gmp, kmax_gmp, b );
                        mpz_mul_ui( kmax_gmp, kmax_gmp, a );
                } else {
                        printf( "Unable to get kmax value from '%s'\n", argv[3] );
                        return(0);
                }
        } else {
                mpz_set_str(kmax_gmp,argv[3],10);
        }
With this you can now do:-

./octo 179 1E14 2E14

instead of all of those zeros.
Greenbank is offline