Week 15 · 15.5 · Fri, Nov 13 · The Bigger Picture: ACT-style reading
A Number Without Its Kind: Mars Climate Orbiter and Java's Types
1 This section explains how a spacecraft was lost because two programs disagreed about what a number meant, and how Java keeps the kind of every value with the value itself.
Lost at Mars
2 Mars Climate Orbiter was launched on December 11, 1998. Its job was to orbit Mars as the first weather satellite at another planet and to relay messages for a lander that would arrive later. Two teams shared the work. Engineers at Lockheed Martin Astronautics in Denver, Colorado, operated the spacecraft, and the navigation team at NASA's Jet Propulsion Laboratory in California steered it toward Mars. On September 23, 1999, the spacecraft fired its engine to go into orbit and passed behind the planet. Its signal was last seen at about 9:04 in the morning, world time, and the spacecraft was lost.
3 A board of investigators published its report on November 10, 1999. It found that the root cause was the failure to use metric units in one piece of ground software, called Small Forces. During the nine-month trip, small thruster firings nudged the spacecraft, and Small Forces wrote down the push from each one. The written agreement between the teams said those numbers had to be in newton-seconds, a metric unit. Small Forces wrote them in pound-seconds instead. The navigation software read every number as newton-seconds. Because one pound of force equals about 4.45 newtons, the navigators underestimated each push by a factor of 4.45. The spacecraft came within about 57 kilometers of Mars, which the board judged too low for it to survive.
A Number Needs Its Kind
4 Nothing was wrong with any single number in the file. Each one was correct for the program that wrote it. The trouble was that the program that read the numbers took them to be a different kind of value. A unit tells what a number measures, and the same number means different amounts in different units. Among its lessons, the board told the next mission to check that units were used the same way everywhere.
5 Java solves a smaller version of this problem inside every program. Every value has a data type, the kind of value it is, and Java keeps that type with the value. An int holds a whole number, a double holds a number that can have a decimal part, a boolean holds true or false, and a String holds text. A box's type is written when the box is declared, and the compiler checks every value stored in it. A line such as int price = 4.75; does not compile, because 4.75 is a double and an int box cannot hold it.
When Types Meet
6 The type of each value also decides what an operator does with it. Division shows this. When both sides of / are ints, Java divides as whole numbers and keeps only the whole part, so 7 / 2 is 3. When one side is a double, Java first changes the other side to a double, so 7 / 2.0 is 3.5. A change from one type to another is called a conversion, and Java makes this one by itself because no part of the number is lost.
7 The + sign changes its job in the same way. Between two numbers it adds, so 7 + 2 is 9. When either side is a String, Java turns the number into text and joins the two sides, so "7" + 2 is the text 72. Figure 1 puts the lost number and these four answers side by side. The lines below show all four answers.
1System.out.println(7 / 2); 2System.out.println(7 / 2.0); 3System.out.println(7 + 2); 4System.out.println("7" + 2);
3 3.5 9 72
8 Java does not make every conversion by itself. It changes an int into a double, because every int value fits in a double, but it will not quietly put a double into an int box, because the decimal part would be lost. The compiler stops the program and asks the programmer to decide.
9 Today's question asks how the type of each value changes the answer when a Java program puts two values together. The type decides the operator's job: two ints divide as whole numbers, a double keeps the decimal part, and a String turns + into joining. The same + gives 9 for 7 + 2 but 72 for "7" + 2. On today's bench, each job is worked by naming the type of every value first and then reading what each operator does with those types.
Summary
10 Mars Climate Orbiter was lost in 1999 because one program wrote numbers in pound-seconds and another program read them as newton-seconds, so the spacecraft flew far too close to Mars. A number is safe to use only when its kind is known. In Java, every value carries a data type, the compiler checks the type of every value stored, and the types on each side of an operator decide whether / keeps the decimal part and whether + adds or joins.
Sources: NASA, Mars Climate Orbiter Mishap Investigation Board Phase I Report, November 10, 1999; NASA Jet Propulsion Laboratory, Mars Climate Orbiter Team Finds Likely Cause of Loss, September 30, 1999; NASA Science, Mars Climate Orbiter; Oracle, The Java Tutorials: Primitive Data Types and Strings; Oracle, The Java Language Specification, Java SE 21 Edition, Chapters 5 and 15; course repository, snippets run with the course JDK.
Read the passage on the left. Answer each question by clicking a choice: the right answer turns green, and a wrong one tells you why. Questions point to paragraph numbers, as on the ACT.
1. Main idea
Which of the following best states the main idea of the passage?
2. Detail
Which of the following is stated in the passage about the Small Forces software?
3. Detail
The passage says the navigators underestimated each push by a factor of 4.45. Which of the following best explains that statement?
4. Words in context
As it is used in paragraph 4, the word unit most nearly means:
5. Inference
Paragraph 4 says nothing was wrong with any single number in the file. This statement suggests that the loss was caused by:
6. Detail
The passage says a line such as int price = 4.75; does not compile. Which of the following best explains why?
7. Detail
The passage says 7 / 2.0 is 3.5. Which of the following gives the reason the passage states for this result?
8. Function
Which of the following best describes the role of paragraph 8 in the passage?
9. Synthesis
Which example from the passage best answers today's question about how a type changes the answer?