TRENDING NEWS

POPULAR NEWS

How To Make A Program Of Ieee 754 Standard Using Java Or C

What data type in C programming supports a 12 digit number?

I thought I'd just add some additional thoughts to husoski's good response.

The requirement (in terms of bits needed) for a 12 digit number is:

        ceil((ln(999999999999+1)) ⁄ (ln(2))) = 40

The C99 standard included the long long type and specified a minimum size for it to be (effectively) 64 bits. C99 specifies a value, not the number of bits, but in twos complement notation, which isn't required but is generally used, that works out to 64 bits minimum. So if you have long long support, you are guaranteed to see enough range to meet your needs with long long.

As husoski also points out, you can use double values. That is, in practice. That is because most implementations use 64-bit floating point formats that are compatible with the IEEE-754 standard. This means 1 sign bit, 11 exponent bits, and 52 (with hidden bit making a pseudo-53) actual bits of mantissa. 52 bits of mantissa is enough to hold 40 bits. So you are golden there, as well.

However... there is a catch with floating point double values. The C99 standard does NOT specify that the double format must use IEEE-754 formats nor does it specify 52 bit mantissas. Instead, it specifies a minimum of 10 decimal digits. This is NOT enough for 12 decimal digits. So some implementations (usually those targeting a non-workstation environment and most especially targeting a small microcontroller of some kind) that are fully conforming C compilers may also NOT handle 12 digits using the double type. Be aware of this possibility.

In most practice, double would work. But then also in most practice long long would be supported, too. So if you are in a situation where long long isn't present, you may also be in a situation where double won't cover you, either.

That is, if you care about portability of your code. Not many really do care. They just want to get a job done and are willing to rewrite things for a different situation if it happens.

Just a note.

How can I scan and print double in C programming?

Some functions of C programming are:In C programming language, printf() function is used to print the “character, string, float, integer, octal and hexadecimal values” onto the output screen.22. We use printf() function with %d format specifier to display the value of an integer variable.3. Similarly, %c is used to display character, %f for float variable, %s for string variable, %lf for double and %x for hexadecimal variable.4. To generate a newline,we use “\n” in C printf() statement.If you need to know the detail information visit Top grade assignment. Top Grade Assignment Help provides assignment help in all best languages including C Programming, C++, Java, Web Programming, Data Structure, SQL, Android, PHP, Visual Basic, OOPS, DOT NET, System Analysis, Cloud Computing and much more from here you can sharpen your basics in any language.Our main services include:Technical Assignment HelpTop Grade AssignmentSystem Analysis and Design Assignment HelpAndroid Assignment Help

Describe the four basic data types. How could we extract the range of values they represent?

Based on the number of bytes which are allocated, we decide the range.

char 1 byte -2^7 to + 2^7-1 ( -128 to 127)
int 2 bytes -2^15 to + 2^15 -1 ( -32768 to 32767)
long 4 bytes -2^31 to +2^31-1

In the case of float and double IEEE 754 standards are used where precision is the one important
float 4 bytes 6 decimals accuracy
double 8 bytes 11 decimals accuracy

Program to display a decimal number two's complement representation in binary and hexadecimal.?

I need an assembly language program to accept a decimal number and display its 2's complement representation in binary and hexadecimal formats. help me... i need it within a week.........

How does a computer language such as Java store and manipulate floating points numbers?

Virtually all modern hardware and software uses IEEE 754.The strictfp keyword requires java implementations to conform fully to IEEE 754. Without it a number of quite technical rules can be varied.It’s impossible to determine how Java stores floating point numbers, though the methods Double.doubleToLongBits() and Double.doubleToRawLongBits() are required to behave as if the internal format is as specified by IEEE 754, all the arithmetic rules are taken from IEEE 754 and most hardware supports it natively.It’s difficult to imagine a good reason why they aren’t stored that way internally.

Why can't we use Bitwise operators on float and double data types?

First, understand how the real numbers are stored. They’re stored in 3 different parts using IEEE 754 std. as,Sign bit (0/1)Exponent bitsSignificant bits/ MantissaFor float= 1 sign bit+8 exponent bits+23 significant bits= 32 bits.Likewise, for double= 1+11+52 = 64 bits.Okay, now let’s see how float x= 7.5 in IEEE 754 standard is stored in memory.Convert 7.5 into binary: [math]0111.10[/math]Represent 0111.10 in standard exponent format (i.e) [math]1.xe^y [/math]where x is significant bits and y is exponent value: [math]1.1110 e^2[/math]Add exponent value (y) to the standard bias value. This bias value is calculated as [math]2^(n-1)-1; [/math]where n is exponent bits size.[math] [/math]For float, the bias value is [math]7f [/math]and for double, it is [math]3ff[/math]. Here, we took float, so: Biased exponent is [math]7f+2 = 127+2 = 129. [/math]Arrange all these fields as in memory (sign bit, exponent bits and mantissa).Image: Internet.Now, back to the question → Why can’t we use bitwise operators on float and double data types? Now think, if you use right shift or left shift on these bits, won’t that collapse everything?

How is a float or double value stored in memory in java?

There used to be a bunch of ways of storing floats and doubles in the bad old days, but they were standardized so that they could be hardware accelerated. Adding hardware acceleration to math was a major trend in computing back in the nineties, and was something of a predecessor to graphics acceleration (which uses floats).Today, basically all floats in all languages use exactly the same storage method: they store a 32 bit integer divided into three parts. Those three parts are called the sign (1 bit), the exponent (8 bits) and the mantissa (23 bits).​The double precision numbers have a similar format, just with more bits and bigger values (1 for the sign, 11 for the exponent, and 52 for the mantissa, specifically). Note that the mantissa in this diagram is called the "fraction."If we call the sign s and consider it equal to 1 or 0, and if we call the exponent part x, and if we call the mantissa part m, then the value of the number is usually:[math]2^{x-151}(1-2s)(m+2^{24})[/math]The value 1.0 is represented with s=0, m=0, x=127, for example. The extra [math]2^{24}[/math] added to m is called the "implicit leading bit," and is there because every binary number in exponent notation (except zero) starts with a 1, so the implied leading bit doesn't need to be stored. Note that this default rule cannot store a zero.There are two important exceptions to this notation:Firstly, if x is 255 (the max value), then the number is illegal, and its meaning depends on m; if m is 0, then it is positive (s=0) or negative (s=1) infinity. If m is not zero, then it is NaN (not-a-number). There are many legal ways to represent NaN, and this is sometimes used to differentiate between cases where NaN ought to throw an exception and where it ought not to.The second case is when x=0. In this case, the formula becomes:[math]2^{-150}(1-2s)m[/math]This allows for an entire range of extra-small numbers, called denormalized numbers, to be generated, and has the double advantage that if you set all the bits to zero, the encoded number is also zero. Another major advantage of this system is that the integer comparisons (<, >, etc) work in nearly the same way for floats and integers!Anyway, hopefully that helped; floats are a dense topic.

TRENDING NEWS