Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unsigned double in C? [duplicate]

Tags:

c

struct

I need to use unsigned double in C structure, but i can't compile. An error says: short, signed or unsigned invalid for `myvar'

this is my code:

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

struct eReg{
   int key;
   unsigned char a;
   unsigned short int b;
   unsigned double myvar;
   }MyReg;

Does anyone know what is wrong?

EDIT I did not know "unsigned double" equals "unsigned float", then I didn't knew I had to find the answer to my question as "unsigned floats in C?" Anyway after reading the post, I've accepted my question as "duplicate". I suggest deleting this question.

like image 945
Roberto Sepúlveda Bravo Avatar asked Jan 07 '23 15:01

Roberto Sepúlveda Bravo


1 Answers

You can not have unsigned floating point types. Therefore no unsigned double or unsigned float. unsigned can only be applied to integer types like char short int and long. The reason we have unsigned integers is that they can store numbers twice as large, and can be better suited for handling binary data. I can't really think of much of an advantage to using unsigned floating point types. You could get a little more precision but this is probably not worth the effort of implementing it in hardware and software.

like image 172
chasep255 Avatar answered Jan 10 '23 04:01

chasep255