Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #24746

Re: "i = i|0"

Newsgroups comp.lang.javascript
Subject Re: "i = i|0"
From "Evertjan." <exxjxw.hannivoort@inter.nl.net>
References <emscripten-20140611221102@ram.dialup.fu-berlin.de>
Date 2014-06-11 22:48 +0200
Message-ID <XnsA349E8160EEAEeejj99@194.109.133.133> (permalink)

Show all headers | View raw


ram@zedat.fu-berlin.de (Stefan Ram) wrote on 11 jun 2014 in 
comp.lang.javascript:

> Newsgroups: comp.lang.c,comp.lang.javascript

Response for comp.lang.javascript
 
>   I have read this in a World-Wide Web encyclopedia:
> 
> For example, given the following C code:
> 
> int f(int i) {
>   return i + 1;
>}

I have no idea what that means.

> Emscripten 

What is that?

> would output the following JS code:
> 
> function f(i) {
>   i = i|0;
>   return (i + 1)|0;
>}

> Do you think that the ť|0Ť is necessary to express the
> C semantics in JavaScript, 

What is "C semantics"?
Why would you want to do that and not just write javascript?
What other types of i would you want to catch?
btw, i could be a string, a floating point, would you allow that?
 

var i = 'Hello';
alert(i|0); // 0
alert(i||0); // Hello

alert('yes'|'maybe'); // 0
alert('yes'||'maybe'); // yes
alert(''||'maybe'); // maybe


> or could the speed of the
> generated code be improved by omitting it?

var i = 'Hello';
alert(f(i));

function f(i) {
   return i++;
};

This will return NaN, 
[which is NOT an error!]
and then you deal with that.

However, better be sure of your code 
and the effective subtypes
of the variable values you are using.

Javascript has no typed variables.


-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

Back to comp.lang.javascript | Previous | Next | Find similar | Unroll thread


Thread

Re: "i = i|0" "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-06-11 22:48 +0200

csiph-web