On May 18, 2:40 pm, (E-Mail Removed) (John Cochran) wrote:

> In article <464e0262$0$13207$(E-Mail Removed)>,

>

>

>

>

>

> Carramba <(E-Mail Removed)> wrote:

> >John Cochran skrev:

> >> In article <464df809$0$13214$(E-Mail Removed)>,

> >> Carramba <(E-Mail Removed)> wrote:

> >>> user923005 skrev:

> >>>> On May 18, 7:15 am, Carramba <(E-Mail Removed)> wrote:

> >>>>> Hi!

> SNIP

>

> >> One thing you haven't mentioned and you should is WHY you are performing

> >> bitwise operations. If you tell us what you are attempting to acomplish,

> >> then we might be able to help you better. And DON'T say that what you need

> >> to do is perform bitwise manipulation of floating point numbers. Do not

> >> simply ask for help on what you believe to be a step in solving your problem,

> >> but instead tell what your actual problem is.

>

> >Some time it's strange that one can't by taken by word and believed ...

> >I'm working with genetic algorithms, and have implemented it in C. in

> >order to work one need to perform crossover and bitflip operations on

> >encoded data.

> >crossover - take two values represented by binary string and, "cast a

> >coin" and exchange part of those strings -> bitmask operation

> >bitflip - cast a coin and flip bit in that place.

>

> >reason one:

> >since this is not forum for genetic algorithms I didn't bother to

> >explain earlier, and it would take more than this little peace to

> >explain in details what I'm doing

> >reason two:

> >because in the I have been shouted and treat malicious then I have

> >posted something that wasn't related to ansi c. and underlying problem

> >isn't so I just posted only what are my intentions to do.

>

> OK, I'm snipping everything that looks like you're getting upset and/or

> insulting or thinking you're being insulted.

>

> If I understand you correctly, you need to do bit operations on something

> larger than what you can get using integers and you think that by using

> floating point numbers, you'll somehow succeed.

>

> Problem: Bit operations on floating point numbers ARE NOT DEFINED AND WILL NOT WORK.

> Period. End of discussion. Case closed.

>

> Additionally, doing said operations on floating point numbers will not get you

> more bits than what you can get by using integral types. To demonstrate, execute

> the following short program.

>

> #include <stdio.h>

>

> int main(void)

> {

> printf("short = %d\n", (int)sizeof(short));

> printf("int = %d\n", (int)sizeof(int));

> printf("long = %d\n", (int)sizeof(long));

> printf("long long = %d\n", (int)sizeof(long long));

> printf("float = %d\n", (int)sizeof(float));

> printf("double = %d\n", (int)sizeof(double));

> printf("long double = %d\n", (int)sizeof(long double));

> return 0;

>

> }

>

> Note: Some implementations of C will not support long long or long double. If so,

> just ommit those lines that mention it.
Those that do not support long double are broken because it is a

requirement of the language.

On the other hand, long double does not have to be larger than double.

> The numbers generated by this simple program is simply the number of bytes each

> type takes up. Multiply by 8 to get the number of bits available for manipulation.

> I would not be surprised if the output of the above program is something like

>

> 2

> 4

> 4

> 8

> 4

> 8

> 10

>

> As you can see, none of the above numbers is really large and is likely to be

> unsuitable for genetic algorithms assuming you need more than about 64 bits.

>

> So since none of the primitive data types available is suitable for you, you'll

> have to use a composite data type and make functions to manipulate them. I'd

> suggest that you use as your basic component an array in integral values with the

> actual integral type dependent on the native word size of your computer. The type

> "unsigned int" comes to mind as a reasonable start. Then write some functions

> designed to create/destroy/manipulate these arrays.

>

> For example:

> (Error checking omitted for clarity. Code untested....)

>

> #include <stdlib.h>

>

> typedef struct {

> size_t len;

> unsigned int *array;

>

> } BIT_ARRAY;

>

> BIT_ARRAY *create_ba(size_t size)

> {

> BIT_ARRAY *p;

>

> p = malloc(sizeof(*p));

> p->len = size;

> p->array = calloc(sizeof(unsigned int), p->len);

> return p;

>

> }

>

> void create_ba(BIT_ARRAY *p)

> {

> free(p->array);

> free(p);

>

> }

>

> BIT_ARRAY *and_ba(BIT_ARRAY *a, BIT_ARRAY *b)

> {

> size_t len,x;

> BIT_ARRAY *p;

>

> len = (a->len < b->len) ? a->len : b->len;

>

> p = create_ba(len);

>

> for(x=0; x<len; ++x) {

> p->array[x] = a->array[x] & b->array[x];

> }

> return p;

>

> }

>

> etc. etc. etc.

>

> Sorry, but this is the best that you can do. And if someone on this group says

> that what you're doing doesn't make sense, it doesn't mean that they think you're

> and idiot. It at worst means that you're ignorant about the language. Just remember:

>

> Ignorance is curable, stupidity isn't.

>

> It's OK to be ignorant if you're willing to be educated. If you're not willing to

> be educated, then I have to assume that you're not ignorant, but instead you're

> stupid. Don't be stupid.- Hide quoted text -
Maybe he wants a multiple precision number library like GMP.

Personally, I am fond of MPFR.

http://pari.math.u-bordeaux.fr/benchs/timings-mpfr.html