![]() | |
#11
| |||
| |||
|
|
Thomas 'PointedEars' Lahn wrote: Thomas 'Ingrid' Lahn wrote: if (input && !isNaN(input = parseInt(input, 10)) s/parseInt/parseFloat/ snip Ahh, you are at that again. parseFloat is certainly needed with your following modulo test over parseInt. I still see some problematic string; "234Z" will look like an integer. |

|
I would suggest a forced type-conversion to a number as that would produce NaN with the preceding string, but that only reduces the possibilities to problems arising from "0x234" and the like. |
#12
| |||
| |||
|
|
Thomas 'PointedEars' Lahn wrote: Thomas 'Ingrid' Lahn wrote: if (input && !isNaN(input = parseInt(input, 10)) s/parseInt/parseFloat/ snip Ahh, you are at that again. parseFloat is certainly needed with your following modulo test over parseInt. I still see some problematic string; "234Z" will look like an integer. |

|
I would suggest a forced type-conversion to a number as that would produce NaN with the preceding string, but that only reduces the possibilities to problems arising from "0x234" and the like. |
#13
| |||
| |||
|
|
Thomas 'PointedEars' Lahn wrote: snip But it seems to me that Vax' solution is the most efficient one here, even more efficient than your RegExp proposal. The use of bitwise AND limits the integer range to only those positive integers that can be expressed as a signed 32 bit integer. We don't know whether that is acceptable, but it is entirely possible that it would |

#14
| |||
| |||
|
|
U¿ytkownik "Richard Cornford" <Richard (AT) litotes (DOT) demon.co.uk> napisa³ w wiadomo¶ci news:c8e1eu$t$1$8302bc10 (AT) news (DOT) demon.co.uk... |
|
Thomas 'PointedEars' Lahn wrote: snip But it seems to me that Vax' solution is the most efficient one here, even more efficient than your RegExp proposal. The use of bitwise AND limits the integer range to only those positive integers that can be expressed as a signed 32 bit integer. We don't know whether that is acceptable, but it is entirely possible that it would We know... |
_Integer_ is 32 bit long, bigger "integer" == float ![]() |
#15
| |||
| |||
|
|
Sure? _Integer_ is 32 bit long, bigger "integer" == float ![]() No. |
#16
| |||
| |||
|
|
Vax wrote: U¿ytkownik "Richard Cornford" <Richard (AT) litotes (DOT) demon.co.uk> napisa³ w wiadomo¶ci news:c8e1eu$t$1$8302bc10 (AT) news (DOT) demon.co.uk... Please do not write attribution novels: http://netmeister.org/news/learn2quote1.html#ss1.2 |
|
But bitwise operators (need to) make the distinction (AIUI operation must be done using the CPU's 32-bit registers [EAX, EBX aso.] after all, even if the compiled bytecode is executed by the VM at first), so your solution is indeed restricted to the signed 32 bit Integer subset of numbers (where "Integer" means the _machine_ data type). |
#17
| |||
| |||
|
|
[...] Sure? _Integer_ is 32 bit long, bigger "integer" == float ![]() No. Ok, ok, in JS we have integer (IEEE)... and integer (binary), |
|
and operators: "^,~,|,&,>>,>>>....." converts integer (IEEE) (and strings, boolean, float etc.) to integer (bin). |
#18
| |||
| |||
|
|
No, in JS (and other ECMAScript implementations) *all* numeric values are double-precision IEEE-754 *floating-point* numbers. |
|
and operators: "^,~,|,&,>>,>>>....." converts integer (IEEE) (and strings, boolean, float etc.) to integer (bin). No, binary operators convert their operands to 32 bit signed Integers |

#19
| ||||
| ||||
|
|
No, in JS (and other ECMAScript implementations) *all* numeric values are double-precision IEEE-754 *floating-point* numbers. If the exponent is "neutral", we have 52-bits, that represents integer. |
|
Of course, "machine format" of the number (all numbers) is still "double". |
|
and operators: "^,~,|,&,>>,>>>....." converts integer (IEEE) (and strings, boolean, float etc.) to integer (bin). No, binary operators convert their operands to 32 bit signed Integers ..."semantic" ![]() |
|
9.6 ToUint32: (Unsigned 32 Bit Integer) The operator ToUint32 converts its argument to one of 2^32 integer values in the range 0 through (2^32)−1, inclusive. This operator functions as follows: 1. Call ToNumber on the input argument. 2. If Result(1) is NaN, +0, −0, +∞, or −∞, return +0. 3. Compute sign(Result(1)) * floor(abs(Result(1))). 4. Compute Result(3) modulo 2^32; that is, a finite integer value k of Number type with positive sign and less than 2^32 in magnitude such the mathematical difference of Result(3) and k is mathematically an integer multiple of 2^32. 5. Return Result(4). NOTE Given the above definition of ToUInt32: Step 5 is the only difference between ToUint32 and ToInt32. The ToUint32 operation is idempotent: if applied to a result that it produced, the second application leaves that value unchanged. ToUint32(ToInt32(x)) is equal to ToUint32(x) for all values of x. (It is to preserve this latter property that +∞ and −∞ are mapped to +0.) ToUint32 maps −0 to +0. [...] 11.7.3 The Unsigned Right Shift Operator ( >>> ) Performs a zero-filling bitwise right shift operation on the left operand by the amount specified by the right operand. The production ShiftExpression : ShiftExpression >>> AdditiveExpression is evaluated as follows: 1. Evaluate ShiftExpression. 2. Call GetValue(Result(1)). 3. Evaluate AdditiveExpression. 4. Call GetValue(Result(3)). 5. Call ToUint32(Result(2)). 6. Call ToUint32(Result(4)). 7. Mask out all but the least significant 5 bits of Result(6), that is, compute Result(6) & 0x1F. 8. Perform zero-filling right shift of Result(5) by Result(7) bits. Vacated bits are filled with zero. The result is an unsigned 32 bit integer. 9. Return Result(8). |
#20
| |||
| |||
|
|
No, binary operators convert their operands to 32 bit signed Integers ..."semantic" ![]() What exactly are you trying to say? |
![]() |
| Thread Tools | |
| Display Modes | |
| |