[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

ram

2/1/2016 10:33:00 AM

< Math.floor()
> NaN

Is this specified by ECMAScript?

»20.2.2 Function Properties of the Math Object« says, »Each
of the following Math object functions applies the ToNumber
abstract operation to each of its arguments«, but then
»7.1.3 ToNumber ( argument )« seems to already assume
that there actually /is/ an argument.

Ok, surely I can guess that »ToNumber ()« is the same as
»ToNumber ( undefined )«, but even in 7 or 7.1, I cannot
find a wording that says so.

5 Answers

ram

2/1/2016 10:45:00 AM

0

ram@zedat.fu-berlin.de (Stefan Ram) writes:
>< Math.floor()
>> NaN
>Is this specified by ECMAScript?

In the meantime, I found this:

»17 ECMAScript Standard Built-in Objects

...

Unless otherwise specified in the description of a
particular function, if a built-in function or
constructor is given fewer arguments than the function
is specified to require, the function or constructor
shall behave exactly as if it had been given sufficient
additional arguments, each such argument being the
undefined value.«

So, I hope that now I have found why »Math.floor()« behaves
like »Math.floor( undefined )«. Please let me know if you
think that the above quotation does /not/ apply here.

Aleksandro

2/1/2016 2:08:00 PM

0

On 01/02/16 07:44, Stefan Ram wrote:
> ram@zedat.fu-berlin.de (Stefan Ram) writes:
>> < Math.floor()
>>> NaN
>> Is this specified by ECMAScript?
>
> In the meantime, I found this:
>
> »17 ECMAScript Standard Built-in Objects
>
> ...
>
> Unless otherwise specified in the description of a
> particular function, if a built-in function or
> constructor is given fewer arguments than the function
> is specified to require, the function or constructor
> shall behave exactly as if it had been given sufficient
> additional arguments, each such argument being the
> undefined value.«
>
> So, I hope that now I have found why »Math.floor()« behaves
> like »Math.floor( undefined )«. Please let me know if you
> think that the above quotation does /not/ apply here.

I don't see why this would not be the case, you give non-numbers to a
function that needs numbers, that's why you won't get a number either.

4ndre4

2/2/2016 7:34:00 PM

0

On 01/02/2016 10:32, Stefan Ram wrote:
[...]
> Ok, surely I can guess that »ToNumber ()« is the same as
> »ToNumber ( undefined )«, but even in 7 or 7.1, I cannot
> find a wording that says so.

Because they are probably assuming that you know the basics of JavaScript:

function myFunction( argument ) {
console.log(argument);
}

myFunction();
myFunction("hello world");

Output:

undefined
hello world

--
4ndre4
"The use of COBOL cripples the mind; its teaching should, therefore, be
regarded as a criminal offense." (E. Dijkstra)

Ben Bacarisse

2/2/2016 11:01:00 PM

0

ram@zedat.fu-berlin.de (Stefan Ram) writes:

> < Math.floor()
>> NaN
>
> Is this specified by ECMAScript?
>
> »20.2.2 Function Properties of the Math Object« says, »Each
> of the following Math object functions applies the ToNumber
> abstract operation to each of its arguments«, but then
> »7.1.3 ToNumber ( argument )« seems to already assume
> that there actually /is/ an argument.
>
> Ok, surely I can guess that »ToNumber ()« is the same as
> »ToNumber ( undefined )«, but even in 7 or 7.1, I cannot
> find a wording that says so.

"Unless otherwise specified in the description of a particular
function, if a built-in function or constructor is given fewer
arguments than the function is specified to require, the function or
constructor shall behave exactly as if it had been given sufficient
additional arguments, each such argument being the undefined value."

?

--
Ben.

Thomas 'PointedEars' Lahn

2/3/2016 4:34:00 PM

0

Ben Bacarisse wrote:

> ram@zedat.fu-berlin.de (Stefan Ram) writes:
>> Ok, surely I can guess that »ToNumber ()« is the same as
>> »ToNumber ( undefined )«, but even in 7 or 7.1, I cannot
>> find a wording that says so.
>
> "Unless otherwise specified in the description of a particular
> function, if a built-in function or constructor is given fewer
> arguments than the function is specified to require, the function or
> constructor shall behave exactly as if it had been given sufficient
> additional arguments, each such argument being the undefined value."
>
> ?

<news:undefined-20160201114012@ram.dialup.fu-berlin.de>

--
PointedEars
FAQ: <http://PointedEars.... | SVN: <http://PointedEars.de...
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-...
Please do not cc me. / Bitte keine Kopien per E-Mail.