<< Chapter < Page Chapter >> Page >

Floating-point types

Floating-point types are a little more complicated than whole-number types. I found the following definition of floating-point in the Free On-Line Dictionary of Computing :

A number representation consisting of a mantissa, M, an exponent, E, and a radix (or "base"). The number represented is M*R^E where R is the radix.

What does this really mean?

I'm not going to get into a long discussion about floating-point values at this point. If you are really interested, you will find a detailed discussion inlesson # 905 at (External Link) .

Advantages of floating-point types

One advantage of floating-point types is that they can be used to maintain fractional parts in data values.

Another advantage of floating-point types is that a very large range of values can be represented using a reasonably small amount of computer memory for storage of the values.

For example (assuming that I counted the number of digits correctly) Figure 3 shows how to represent a very large value and a very small value as a floating-point type.

Figure 3 . Representing a large range of values.

The very large value: 62357185000000000000000000000000000000.0

can be represented as

6.2357185E+37

The very small value:

0.0000000000000000000000000000062357185

can be represented as 6.2357185E-30

When would you use floating-point?

If you happen to be working in an area where you need to keep track of fractional parts (such as the amount of hamburger in a package) , have to work with extremely large numbers (distances between galaxies) , or have to work with extremely small values (the size of atomic particles) , then you will need to use the floating-point types.

Also, if you will be doing computations involving division, floating-point is often easier to work with because division with integer typescan be problematic. (The remainder is discarded in integer division, which can cause arithmetic accuracy problems.)

Two floating-point types

Java supports two different floating-point types:

  • float
  • double

These two types differ primarily in terms of the range of values that they can support and the number of significant digits used in the representation of those values.

Figure 4 shows the smallest and largest values that can be accommodated by each of the floating-point types. Values of either type can be either positive or negative.

Figure 4 . Value range for floating-point types.
  • float: 1.4E-45 to 3.4028235E38
  • double: 4.9E-324 to 1.7976931348623157E308

Exclude type float

As you saw earlier , the authors of the exam have excluded type float including only type double (of the two floating-point types) in the exam. If one of the floating-point types is to be excluded, type double is the logical choice to keep. In many ways, it is the default floating-point type inJava. For example, a literal value, such as 3.14159, is considered to be type double unless you write code to force it to be treated as type float .

The boolean type

The boolean type is the simplest type supported by Java. It can have only two values:

  • true
  • false

Generally speaking, about the only operations that can be applied to an instance of the boolean type are to change it from true to false, and vice versa. The boolean type is commonly used in some kind of a test to determine what to do next.

Questions & Answers

what does preconceived mean
sammie Reply
physiological Psychology
Nwosu Reply
How can I develope my cognitive domain
Amanyire Reply
why is communication effective
Dakolo Reply
Communication is effective because it allows individuals to share ideas, thoughts, and information with others.
effective communication can lead to improved outcomes in various settings, including personal relationships, business environments, and educational settings. By communicating effectively, individuals can negotiate effectively, solve problems collaboratively, and work towards common goals.
it starts up serve and return practice/assessments.it helps find voice talking therapy also assessments through relaxed conversation.
miss
Every time someone flushes a toilet in the apartment building, the person begins to jumb back automatically after hearing the flush, before the water temperature changes. Identify the types of learning, if it is classical conditioning identify the NS, UCS, CS and CR. If it is operant conditioning, identify the type of consequence positive reinforcement, negative reinforcement or punishment
Wekolamo Reply
please i need answer
Wekolamo
because it helps many people around the world to understand how to interact with other people and understand them well, for example at work (job).
Manix Reply
Agreed 👍 There are many parts of our brains and behaviors, we really need to get to know. Blessings for everyone and happy Sunday!
ARC
A child is a member of community not society elucidate ?
JESSY Reply
Isn't practices worldwide, be it psychology, be it science. isn't much just a false belief of control over something the mind cannot truly comprehend?
Simon Reply
compare and contrast skinner's perspective on personality development on freud
namakula Reply
Skinner skipped the whole unconscious phenomenon and rather emphasized on classical conditioning
war
explain how nature and nurture affect the development and later the productivity of an individual.
Amesalu Reply
nature is an hereditary factor while nurture is an environmental factor which constitute an individual personality. so if an individual's parent has a deviant behavior and was also brought up in an deviant environment, observation of the behavior and the inborn trait we make the individual deviant.
Samuel
I am taking this course because I am hoping that I could somehow learn more about my chosen field of interest and due to the fact that being a PsyD really ignites my passion as an individual the more I hope to learn about developing and literally explore the complexity of my critical thinking skills
Zyryn Reply
good👍
Jonathan
and having a good philosophy of the world is like a sandwich and a peanut butter 👍
Jonathan
generally amnesi how long yrs memory loss
Kelu Reply
interpersonal relationships
Abdulfatai Reply
What would be the best educational aid(s) for gifted kids/savants?
Heidi Reply
treat them normal, if they want help then give them. that will make everyone happy
Saurabh
What are the treatment for autism?
Magret Reply
hello. autism is a umbrella term. autistic kids have different disorder overlapping. for example. a kid may show symptoms of ADHD and also learning disabilities. before treatment please make sure the kid doesn't have physical disabilities like hearing..vision..speech problem. sometimes these
Jharna
continue.. sometimes due to these physical problems..the diagnosis may be misdiagnosed. treatment for autism. well it depends on the severity. since autistic kids have problems in communicating and adopting to the environment.. it's best to expose the child in situations where the child
Jharna
child interact with other kids under doc supervision. play therapy. speech therapy. Engaging in different activities that activate most parts of the brain.. like drawing..painting. matching color board game. string and beads game. the more you interact with the child the more effective
Jharna
results you'll get.. please consult a therapist to know what suits best on your child. and last as a parent. I know sometimes it's overwhelming to guide a special kid. but trust the process and be strong and patient as a parent.
Jharna
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Ap computer science a, clarification of the java subset. OpenStax CNX. Oct 03, 2015 Download for free at https://legacy.cnx.org/content/col11279/1.5
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Ap computer science a, clarification of the java subset' conversation and receive update notifications?

Ask