in reply to Re^3: Weird behavior of int()
in thread Weird behavior of int()

Look at the official documentation:

"Returns the integer portion of EXPR"

That's incorrect and vague

At the very least, this documentation needs fixing - even if the underlying code is not getting touched.

Replies are listed 'Best First'.
Re^5: Weird behavior of int()
by syphilis (Archbishop) on May 28, 2024 at 01:36 UTC
    NaN and Inf are not integers

    That's true - for completeness, the documentation should probably specify that int($x) returns $x, as evaluated in numeric context, if $x (as evaluated in numeric context) is either NaN or +Inf or -Inf or has no fractional part.

    What does 'integer portion' actually mean? It's not defined, so one could read that to mean that the integer portion of eee5 is 5.

    Maybe it should be specified that EXPR is first evaluated in numeric context, and the integer portion of that derived value is returned.
    But then, neither the sin() nor cos() nor log() nor exp() nor sqrt() documentations specify that EXPR is to be evaluated in numeric context.
    Do those docs need to make the same clarification ?

    One might argue that it's somehow already clear that those math functions will evaluate their args in numeric context, but that it's not immediately apparent that int() will do the same.
    I don't think I'd agree with that argument ... nor would I necessarily disagree with it ... dunno ;-)

    You should present you point of view at https://github.com/Perl/perl5/pull/22227.

    Cheers,
    Rob