Interestingly some numbers can be perfectly represented in Base 10, but not in Base 2. An example is one-tenth (in Base 10, this is 0.1; in Base 2 this is a repeating decimal. Suppose we set both f and g to one-tenth using the statements below. f = 0.1; g = 0.1; Answer the following questions. For each, mark the best answer. Which will be closer to the actual value of one-tenth? f g Which can hold higher values? f g Which takes more memory? f g When using real values I should always use type double, to be safe. True False

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
icon
Concept explainers
Question

Interestingly some numbers can be perfectly represented in Base 10, but not in Base 2. An example is one-tenth (in Base 10, this is 0.1; in Base 2 this is a repeating decimal. Suppose we set both f and g to one-tenth using the statements below. f = 0.1; g = 0.1; Answer the following questions. For each, mark the best answer. Which will be closer to the actual value of one-tenth? f g Which can hold higher values? f g Which takes more memory? f g When using real values I should always use type double, to be safe. True False

Java and C have two ways to declare real values:
float (32 bits) and double (64 bits).
Each of these use the IEEE Floating Point Standard, with the following number of
bits for the sign, exponent and mantissa:
Standard
32-bit (float)
64-bit (double)
Sign
1
1
Exponent
8
11
Mantissa
23
52
Transcribed Image Text:Java and C have two ways to declare real values: float (32 bits) and double (64 bits). Each of these use the IEEE Floating Point Standard, with the following number of bits for the sign, exponent and mantissa: Standard 32-bit (float) 64-bit (double) Sign 1 1 Exponent 8 11 Mantissa 23 52
Expert Solution
Step 1: Introduction:Understanding Floating Point Representation in Java and C

In computer science, floating-point numbers are a crucial aspect of numerical computing. Both Java and C provide two main types for storing real numbers: float and double. These types follow the IEEE 754 standard for floating-point arithmetic, specifying how many bits are to be used for the sign, exponent, and mantissa for each. This answer will explore the differences between float and double in relation to representing the value one-tenth (0.1), covering aspects such as accuracy, value range, and memory consumption. Moreover, it will address the common notion that one should always use double for real values to be on the safe side.


steps

Step by step

Solved in 6 steps

Blurred answer
Knowledge Booster
Operators
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education