GfG QA is closing soon... Please refer PRACTICE or GfG now on wards !!

how to create a user define variable it's range is 2^-127 to 2^127 ?

in c langauge ......

asked Oct 21, 2016 by Cvnsaikumar

1 Answer

As byte is the least accessible memory; I believe the range values you mentioned must be 2^128 instead of 2^127.

Hence, with my assumptions:  Total bytes = 128/8 = 16 bytes required to hold a value of that range.


Consider signed char; sizeof(char) = 1 i.e., 8 bits. Its range is -(2^8) to (2^8)-1.

To increase this range:

-(2^8) * x = -(2^128)  => x = 2^120 i.e., you require 120/8=15 extra bytes to hold the value of that range

Hence, the defined structure could be more or less like:

struct myvar {

    char p[16];


I believe one also has to make sure about the endianness of the system because if you want to perform arithmetic/logical operations on your variable, you need to know how to compute them.

I hope someone could validate my answer here  !!

answered Oct 21, 2016 by GaAl

please give one example by performing any arithmetic operation on this variable..........