New Operator
I have been pushing for this in the past on several occasions, but enthusiasm in the WG has been scant, unfortunately. Maybe I haven't been pushing hard enough.
An HTML attachment was scrubbed... URL: esdiscuss/attachments/20080305/b96fd2db/attachment-0002
Well, that would certainly make the new language popular with the slashdot crowd....
(sorry, couldn¹t resist)
What about % just like in C syntax family languages ?
Na , Michael O'Brien <mob at mbedthis.com> escreveu:
Oh sorry...not % at all. % is for the remainder. Sorry.
Michael O'Brien <mob at mbedthis.com> escreveu:
2008/3/5 Michael O'Brien <mob at mbedthis.com>:
I'll vote for that also. It improves readability quite a bit.
But is there a better operator than ""?
Shame "//" is taken. What about "/."
I thought that's what the proposed "div" operator was.
Just \ would work if we're happy with not allowing its use at the end of a line. A little dodgy, syntactically, IMO. I've advocated "\" in the past, which by normal lexing rules would be unambiguous by the longest-token lexing rule.
("/." is ambiguous, consider 3/.5.)
For the record (and top-quoting, ugh), I regret not putting integer
division into JS back in the day. I would have called it 'div',
though, not '': 'a div b'. Wirth and his teaching language left old
impressions.
Don't you want to be able to express rounding mode? And if so, do you
need 4 operators? floor/, ceiling/, round/, truncate/? Oh, maybe they
should be named /-, /+, /~ and /0. Yow.
Is div truncate/, or round/? I can never remember.
Tucker,
I detect sarcasm in your reply, but maybe I'm just being paranoid now...
R4RS Scheme:
"For integers n1 and n2 with n2 not equal to 0,
(= n1 (+ (* n2 (quotient n1 n2)) (remainder n1 n2)))"
E262-3 (the % operator):
"In the remaining cases, where neither an infinity, nor a zero, nor NaN is involved, the floating-point remainder r from a dividend n and a divisor d is defined by the mathematical relation r = n − (d * q) where q is an integer that is negative only if n/d is negative and positive only if n/d is positive, and whose magnitude is as large as possible without exceeding the magnitude of the true mathematical quotient of n and d."
Div truncates and the definition is machine independent and complements that of %.
Since / rounds (among other operators) but there is no way to control its rounding mode, I don't know why 'div' should have that control either, necessarily.
I'm just relating personal experience, which is that when I need
integer division, I usually need to express the rounding mode too. So
it seems odd to me to provide truncate as an operator, whereas the
other rounding modes require a function call. (Perhaps I would be
less paranoid if I had not been repeatedly bitten by the C 'standard'
which leaves % and / implementation-dependent over parts of their
domain.) I'd rather see the rounding functions extended to 2-argument
versions.
The existence of % does support having its complement, in the absence
of multiple-value returns.
I don't understand your remark about / rounding. Isn't it just inexact?
On 3/6/08, P T Withington <ptw at pobox.com> wrote:
I'm just relating personal experience, which is that when I need integer division, I usually need to express the rounding mode too. So it seems odd to me to provide truncate as an operator, whereas the other rounding modes require a function call. (Perhaps I would be less paranoid if I had not been repeatedly bitten by the C 'standard' which leaves % and / implementation-dependent over parts of their domain.) I'd rather see the rounding functions extended to 2-argument versions.
The existence of % does support having its complement, in the absence of multiple-value returns.
I don't understand your remark about / rounding. Isn't it just inexact?
Sure / can return inexact results, but the inexactness is not arbitrary. It's a result of the selected precision (single/double/extended) and rounding mode. I wish I could be more specific, but my IEEE doc is not where I am right now. (Nothing on the open 'net seems to be quite specific enough.) The wikipedia page for IEEE754 lists four rounding modes for binary floating point. Decimal floating point has more.
Maybe the confusion is regarding "rounding to selected precision" vs "rounding to integer". I'm talking about the former.
An HTML attachment was scrubbed... URL: esdiscuss/attachments/20180213/e146e4ff/attachment
Please do some research before posting in the future.
[1] esdiscuss.org/topic/or-equal-operator [2] esdiscuss.org/topic/proposing-a-conditional-assignment-or-equals-operator [3] esdiscuss.org/topic/new-assignment-operators-not-bit-wise-or [4] esdiscuss.org/topic/please-add-orequal-operator [5] esdiscuss.org/topic/is-much-needed [6] esdiscuss.org/topic/operators-and [7] esdiscuss.org/topic/logical
Is it too late to propose an integer division operator into the spec? Ido quite a bit of WSH programming in both VBScript an JScript andsometimes its a bit of an irritant during a translation, it would benice to see this operator "" available in the new ECMAScript insteadof having to rely on more inefficient workarounds:
VBScript: Dim result result = 19 \ 4 '(result = 4)
JScript: www.codingforums.com/showthread.php?t=58799