Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / PHP

INF

INF is the positive floating-point infinity, and negation produces negative infinity.

Version: PHP 8.4; repository runtime, production runtime not attested

Syntax

is_infinite(INF)

INF is the positive floating-point infinity, and negation produces negative infinity. Both are non-finite and compare above or below finite numbers respectively. Subtracting positive infinity from itself produces NaN, which is tested with is_nan. Standard JSON has no representation for infinity, so JSON_THROW_ON_ERROR raises JsonException.

echo json_encode([is_float(INF), is_infinite(-INF), INF > PHP_FLOAT_MAX, is_nan(INF - INF)]), PHP_EOL;
try { json_encode(INF, JSON_THROW_ON_ERROR); } catch (JsonException $e) { echo get_class($e); }
[true,true,true,true]
JsonException

Examples

<?php
echo json_encode([is_float(INF), is_infinite(-INF), INF > PHP_FLOAT_MAX, is_nan(INF - INF)]), PHP_EOL;
try { json_encode(INF, JSON_THROW_ON_ERROR); } catch (JsonException $e) { echo get_class($e); }

Result

[true,true,true,true]
JsonException

Sources