PHP Numbers Basics Quiz

Quiz 4 9 questions

Prerequisites for the quiz

  1. PHP Numbers Basics

Are you ready?

9 questions to solve

Instructions
  1. This quiz goes to full-screen once you press the Start button.
  2. At the end of the quiz, you are able to review all the questions that you answered wrong and see their explanations.
PHP has two different types for integers and floats. True or false?
Yes, PHP indeed has two different types for integers and floats. They are usually known as the int and float types. Refer to PHP Numbers Basics for more information.
What does 3 / 2 return?
The / operator in PHP does not perform integer division when both of its operands are integers. This means that it does not return 1, but rather 1.5. Hence, the correct choice is (B). Refer to PHP Numbers Basics for more information.
What does 4 / 2 return?
The division operator (/) in PHP returns an integer if the result of the division is an integer. Therefore 4 / 2 returns 2, NOT 2.0. This goes with choice (A). Refer to PHP Numbers Basics for more information.
What does 1E+3 return?
The E symbol in PHP denotes numbers in scientific notation, also known as E notation. The number preceding it represents the significand while the number following it represents a power of 10. Moreover, it always evaluates down to a float.

Hence, 1E+3 represents the number 1000.0, which goes with choice (C). Refer to PHP Numbers Basics for more information.
What does the following code output?
<?php

echo 1_000;
The underscore (_) character as used in a numeric literal is just meant for increasing the readability of the literal. It is removed by the PHP scanner when parsing the code. Hence, 1_000 is merely the integer 1000 and therefore 1000 is output. This goes with choice (A). Refer to PHP Numbers Basics for more information.
What does NAN === NAN return?
According to the IEEE-754 format used internally to represent floats in PHP, two NAN values aren't considered equal to one another and therefore can't be compared via === (or ==). This means that NAN === NAN returns false. Hence, the correct choice is (B). Refer to PHP Numbers Basics for more information.
How to check if a float $f (which is positive and less than 50) is an integral number i.e. has a fractional part equal to 0?
What does 3e100000 resolve down to?
3e100000 represents an extremely large float, that can't be held on in Python's double-precision format. Python evaluates it to inf i.e infinity. Hence, the correct choice is (A). For more details, refer to Python Number Basics — floats.
Which of the following functions is used to determine if a value is NAN?
The correct function is is_nan() and this goes with choice (C). Refer to PHP Numbers Basics — Special Numbers for more information.