I'm using javascript to grab the page url and cut it up so that
variables can be passed- eg images.html?img=23 returns an argument
args[arg] what I can use to display an image from an array.
The problem only comes when I want to perform an action on the
variable.
I can say:
thispage = args[arg]
//This returns the value of the current page.
previouspage = (thispage -1)
//This works ok- it's the page number minus one.
nextpage = (thispage +1)
//This doesn't work. It returns the pagenumber with a 1 appended on
the end. ie if the page was 23 I would get 231.
I've tried -- and ++ aswell, but I can't get the result I want.
How do I do this? 5 2282
"Lasse Reichstein Nielsen" <lr*@hotpop.com> wrote in message
news:4r**********@hotpop.com...
<snip> A string. A number (64 bit IEEE double precision floating point). A boolean. A reference (to an object or a function. References to objects include references to the - null - object and functions are really function objects.) Or undefined. It makes sense to group functions and objeccts, or objects and null, but not both at the same time. To a programmer, the "typeof" operator tells the type of a value. It groups objects and the null value, but distinguishes functions and objects. Internally, functions are objects, but the null value is its own type.
A reasonable point. typeof may insist that null is an object which
implies that there is a null object and the variable would hold a
reference to it, but the last thing that null will ever do is behave as
if it was an object and null is separately categorised in the spec.
<snip>I noted the time taken, and then changed the assignment to x into +"4.4E+4"; Number("4.4E+4") parseFloat("4.4E+4") and compared the times. The results were (approximatly averaged): Base unary + Number parseFloat IE6 1100 1600 2730 2830 Moz 1180 2100 7300 6700 Op7 2150 2800 4520 5320 (on a 1GHz Athlon CPU)
The unary + is indeed much faster, although neither takes significant time. If you only do a few conversions, the efficiency is not worth caring about, but if you get into the tens of thousands or more, then the diffrerence is measurable.
That is, only optimize the inner loop. Or, as a saying goes: "10% of the code takes 90% of the execution time".
Maybe its my obsession with absolute performance but I am inclined to
think that when one approach is objectively optimum then there needs to
be a positive reason for not using it in any context no matter how small
the individual gains. Unary + though is also very short so its use will
reduce the download slightly (even if parenthesised for code clarity).
Incidentally, when I was speed testing the various methods I noticed
that there is quite a variation in performance with different input.
Obviously the length of the string has an influence but also the nature
of the number. If the number is easily represented as an IEEE double
precision float (2 for example) the conversion is faster than when the
result needs some approximation in its representation. But as I recall
the most noticeable differences were when type converting string that
would result in NaN. Though integers that exceed the largest integer representable will end up as floats with exponents.
As they would with Number, parseFloat or parseInt or when written as literals. Since Javascript has only one number type, and it corresponds to IEEE 754 double-precission (64 bit) floating point numbers, it can only represent all integers up to 2^54 exactly. The ones below that limit are also floats with exponents, only the exponent is zero. The ones above need to have exponents larger than zero, and therefore can't range over all the numbers.
I was considering not even mentioning the limit on integers, I figured
that if the site has 2^54 pages the visitor will die of old age before
they get to 2^54+1 ;-)
Richard.
JRS: In article <MP************************@news-server.nc.rr.com>,
seen in news:comp.lang.javascript, Dan Brussee <dbrussee@NOTbetterwaycom
puting.com> posted at Tue, 8 Jul 2003 00:08:55 :- The reason it does not work with + is that the plus is both the addition and concatenation operator.
// It is also the unary + operator.
Since all variables in javascript are the same, if you happen to know you are going to add 2 numeric variables, you should "parse" them. If integers, use parseInt(var, 10) where 10 is the radix (or base) of the number. In your case, I would use:
nextpage = (parseInt(thispage, 10) + 1);
or nextpage = +thispage + 1
Just be sure that thispage will never overflow as an integer
Javascript numbers are floats. All positive integer values up to and
including 2^53 = +9,007,199,254,740,992 can be stored exactly, so 1 can
be added to all but the last; adding 1 to the last has no effect. There
will be no overflow.
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> JS maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.
JRS: In article <be*******************@news.demon.co.uk>, seen in
news:comp.lang.javascript, Richard Cornford
<Ri*****@litotes.demon.co.uk> posted at Tue, 8 Jul 2003 02:53:41 :- Though integers that exceed the largest integer representable will end up as floats with exponents.
<pedant> I think you want to think that out again.
Integers become sparse above 2^53 ~ 9.007e15 ; but 2^69, if converted to
string, is of form /\d+/.
The largest /\d+/ in code which gives a Number which converts to /\d+/
is 999999999999999934469 , which converts to 999999999999999900000 .
The largest integer representable must be (2^53-1)*2^lots, and is about
1.7e308 .
The smallest positive integer not representable in 2^53+1 =
9007199254740993 .
</pedant>
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> JS maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.
JRS: In article <4r**********@hotpop.com>, seen in
news:comp.lang.javascript, Lasse Reichstein Nielsen <lr*@hotpop.com>
posted at Tue, 8 Jul 2003 11:41:09 :- Since Javascript has only one number type, and it corresponds to IEEE 754 double-precission (64 bit) floating point numbers, it can only represent all integers up to 2^54 exactly. The ones below that limit are also floats with exponents, only the exponent is zero.
Typo for 2^53 ?
In IEEE 754 double-precision, we have (see <URL: http://www.merlyn.demon.
co.uk/pas-type.htm#FF>) Sign (1), Exponent (11), Mantissa (52); but that
is the fractional part of the mantissa, and there is an implicit binary
'1.' preceding it. Not, AFAICS, that the structure is exposed in
javascript.
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/&c., FAQqy topics & links;
<URL:http://www.merlyn.demon.co.uk/clpb-faq.txt> RAH Prins : c.l.p.b mFAQ;
<URL:ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip> Timo Salmi's Turbo Pascal FAQ.
Dr John Stockton <sp**@merlyn.demon.co.uk> writes: Typo for 2^53 ?
Yes. :(
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.' This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Paul |
last post by:
This method:
static void swap(int a, int b) {
int c = a;
a = b;
b = c;
}
does not swap the values of a and b over. It doesn't work for String
variables either. However the following method...
|
by: sivaprasad06 |
last post by:
Hi,
I have a editable combo box editor as a cell editor for JTable.
I want use only key board to enter data into jtable. so i am using
ALT+Down comobination for making cell editiable in the...
|
by: CJ |
last post by:
Okay, same program, different issue. Thanks to the help that I was
given I was able to complete my program to find variables in a list that
were repeated, and display them once, and how many times...
|
by: ex_ottoyuhr |
last post by:
I'm trying to create a function that can take arguments, say, foo and
bar, and modify the original copies of foo and bar as well as its local
versions -- the equivalent of C++ funct(&foo, &bar).
...
|
by: mosfet |
last post by:
Hi,
I have a class defined like this :
class CScreenLib
{
public:
CScreenLib(void);
~CScreenLib(void);
|
by: Zytan |
last post by:
I see that static is more restricted in C# than in C++. It appears
usable only on classes and methods, and data members, but cannot be
created within a method itself. Surely this is possible in...
|
by: David Veeneman |
last post by:
Should a member variable be passed to a private method in the same class as
a method argument, or should the method simply call the member variable?
For years, I have passed member variables to...
|
by: amygdala |
last post by:
Hi all,
I'm starting this new project in which I'ld like to implement sort of a
design pattern I have seen being used in the CodeIgniter framework.
Basically, the site will examine the URI and...
|
by: weaknessforcats |
last post by:
C++: The Case Against Global Variables
Summary
This article explores the negative ramifications of using global variables. The use of global variables is such a problem that C++ architects have...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |