Wikipedia:Reference desk/Archives/Computing/2012 April 24

Computing desk
< April 23 << Mar | April | May >> April 25 >
Welcome to the Wikipedia Computing Reference Desk Archives
The page you are currently viewing is an archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages.


April 24

edit

Javascript unlimited multiplier.

edit

What's the best possible way to make a multiplication in javascript without getting exponential number or "Infinity". 190.158.212.204 (talk) 02:15, 24 April 2012 (UTC)[reply]

I don't know about Java specifically, but, in general, the only way to support an unlimited length number, whether integer or real, without going to exponents and/or hitting a precision limit, is to store it as a character string and do all the calculations manually. This is quite painful. StuRat (talk) 03:10, 24 April 2012 (UTC)[reply]

Is this okay?

Extended content
function fullADD(first, second) {
  /*This is a full adder. It is different from javascript add because this can add big numbers without getting exponenential results, or 'Infinity' when there are big numbers, you have to pass the 2 numbers as a string.
I'm not really good at math, or javascript so this is probably a really bad way to do it.*/
  cal = new Object
  cal.FirstString = first.toString()
  SecondString = second.toString()
  cal.Firstt = [];
  for (ANumber = 0; ANumber < cal.FirstString.length; ANumber++) {
    b = cal.FirstString.substring(cal.FirstString.length - 1 - ANumber, cal.FirstString.length - ANumber);
    cal.Firstt[ANumber] = b
  };
  cal.Secondd = [];
  for (ANumber = 0; ANumber < SecondString.length; ANumber++) {
    b = SecondString.substring(SecondString.length - 1 - ANumber, SecondString.length - ANumber);
    cal.Secondd[ANumber] = b
  };
  cal.Secondd
  if (cal.Secondd.length <= cal.Firstt.length) {
    Firs1 = cal.Firstt;
    Secon2 = cal.Secondd
  } else {
    Secon2 = cal.Firstt;
    Firs1 = cal.Secondd
  }
  IsSecondNumberDefined = true;
  Offset = false;
  ArrayResult = []
  for (Num = 0; Num <= Firs1.length; Num++) {
    if (typeof Firs1[Num] == "undefined") {
      off = (Offset) ? 1 : 0;
      if (off == 0) {
        break
      } else {
        ArrayResult[Num] = 1;
        break;
      }
    };
    if (typeof Secon2[Num] == "undefined") {
      off = (Offset) ? 1 : 0;
      Pri = Firs1[Num] * 1 + off;
      IsSecondNumberDefined = false
    };
    if (IsSecondNumberDefined) {
      if (Offset) {
        Pri = (Firs1[Num] * 1) + (Secon2[Num] * 1) + 1
      } else {
        Pri = (Firs1[Num] * 1) + (Secon2[Num] * 1)
      };
    }
    IsSecondNumberDefined = true
    Pri2 = Pri.toString();
    if (Pri2 >= 10) {
      Pri2 = (Pri2 * 1 - 10).toString();
      Offset = true
    } else {
      Offset = false
    }
    ArrayResult[Num] = Pri2
  }
  if (ArrayResult.length > 1) {
    TheResult = (ArrayResult.reverse() + "").replace(/,/g, "")
  } else {
    TheResult = ArrayResult.toString()
  };
  return TheResult
}
function decADD(FirstDec, SecondDec) {
/* This thing just enables decimal addition like 3.2+5.4
It counts the numbers after the "." removes the dots adds them and then adds the "." to the final result*/
  NumbersAfterTheDot1 = (FirstDec.length - 1) - (FirstDec.indexOf("."));
  NumbersAfterTheDot2 = (SecondDec.length - 1) - (SecondDec.indexOf("."));
  if (NumbersAfterTheDot1 < NumbersAfterTheDot2) {
    CUT = NumbersAfterTheDot2;
    DifferenceOfNumbersAfterTheDot = NumbersAfterTheDot2 - NumbersAfterTheDot1;
    AddingZeroes = FirstDec.replace(/\./, "");
    for (k = 0; k < DifferenceOfNumbersAfterTheDot; k++) {
      AddingZeroes += "0";
      NumberWithoutDots = SecondDec.replace(/\./, "")
    }
  } else if (NumbersAfterTheDot2 == NumbersAfterTheDot1) {
    CUT = NumbersAfterTheDot2;
    DifferenceOfNumbersAfterTheDot = NumbersAfterTheDot1;
    AddingZeroes = FirstDec.replace(/\./, "");
    NumberWithoutDots = SecondDec.replace(/\./, "")

  } else {
    CUT = NumbersAfterTheDot1;
    DifferenceOfNumbersAfterTheDot = NumbersAfterTheDot1 - NumbersAfterTheDot2;
    AddingZeroes = SecondDec.replace(/\./, "");
    for (k = 0; k < DifferenceOfNumbersAfterTheDot; k++) {
      AddingZeroes += "0";
      NumberWithoutDots = FirstDec.replace(/\./, "")
    }
  };
  ThaNum = fullADD(NumberWithoutDots, AddingZeroes);
  fir = ThaNum.slice(0, ThaNum.length - CUT);
  sec = ThaNum.slice(ThaNum.length - CUT);
  return fir + "." + sec
}

function add(fir, sec) { /*Global adding function*/
  if (typeof fir == "number") {
    fir = fir.toString()
  }
  if (typeof sec == "number") {
    sec = sec.toString()
  }
  if (/[^0-9\.,]/.test(fir) || /[^0-9,\.]/.test(sec)) {
    return "ERROR: Please use numbers as a string"
  }
  if (/[\.,]/.test(fir) || /[\.,]/.test(sec)) {
    if (/\./.test(fir)) {
      if (fir.match(/[\.,]/g).length > 1) {
        return "Error, you can't add comas or dots more than once. (comas and dots trigger the decimal calculator)"
      }
    }
    if (/\./.test(sec)) {
      if (sec.match(/[\.,]/g).length > 1) {
        return "Error, you can't add comas or dots more than once. (comas and dots trigger the decimal calculator)"
      }
    };
    if (!(/\./.test(fir))) {
      fir = fir + ".0"
    };
    if (!(/\./.test(sec))) {
      sec = sec + ".0"
    }
    return decADD(fir, sec).replace(/0+$/g, "")
  }
  return fullADD(fir, sec)
}

function fullMUL(FirstNumber, SecondNumber) {
  Multplic = new Object
  Multplic.d = FirstNumber
  Multplic.c = SecondNumber
  Multplic.tumbt = [];
  for (aNu = 0; aNu < Multplic.d.length; aNu++) {
    SpmeNumber = Multplic.d.substring(Multplic.d.length - 1 - aNu, Multplic.d.length - aNu);
    Multplic.tumbt[aNu] = SpmeNumber
  };
  Multplic.tr = [];
  for (aNu = 0; aNu < Multplic.c.length; aNu++) {
    SpmeNumber = Multplic.c.substring(Multplic.c.length - 1 - aNu, Multplic.c.length - aNu);
    Multplic.tr[aNu] = SpmeNumber
  };
  Multplic.tr
  if (Multplic.tr.length <= Multplic.tumbt.length) {
    Fi1 = Multplic.tumbt;
    Se2 = Multplic.tr
  } else {
    Se2 = Multplic.tumbt;
    Fi1 = Multplic.tr
  }
  MultiplicArray = [];
  O = 0;
  ArrayOfTheFirstLoop = [];
/*Here there are 2 for loops, it is for multiplicating arrays.. 
For example 56*87, (first loop) it takes the "6" (second loop) Multiplies for 7 and 8,
 then it takes the(first loop) "5" and multiplies (second loop) for 7 and 8 then reverses. adds zeros
And adds them
O is Offset
liO and Shup are random variables. Each of one means the number of the string
Example: 5642x46  Shup= 3 and liO = 1, would mean 4*5 (Remember arrays start from Zero)
(If you still don't understand please see below)
(second number) Se2=["6","4"] 
Fi1= ["2","4","6","5"]
Se2[0]*Fi1[0]=12
Instead of Zeros we use liO and Shup, 
in this case liO would range from 0 to 4 on 4 checks if it is undefined and see if there is an offset)
Shup would range from 0 to 1. For each Shup liO loops from 0 to 4.
Se2[Shup]*Fi1[liO]
And thats what those for loops do. (sorry about silly names, Normally I use short names to type them faster.)
*/
  for (Shup = 0; Shup < Se2.length; Shup++) {
     for (liO = 0; liO <= Fi1.length; liO++) {
      if (typeof Fi1[liO] == "undefined") {
        ArrayOfTheFirstLoop[liO] = O + "";
        MultiplicArray[Shup] = ArrayOfTheFirstLoop.reverse().toString().replace(/,/g, "");
        break
      }
      Tiy = (Se2[Shup] * Fi1[liO] + O * 1).toString();
      if (Tiy.length > 1) {
        yesn = Tiy.substring(1);
        O = Tiy.substring(0, 1)
      } else {
        O = 0;
        yesn = Tiy
      };
      ArrayOfTheFirstLoop[liO] = yesn
    }
    O = 0
  }
  ArrayWithAddedZeros = [];
  for (Some = 0; Some < MultiplicArray.length; Some++) {
    EachNumberWithZeroes = MultiplicArray[Some];
    for (k = 0; k < Some; k++) {
      EachNumberWithZeroes += "0";
    }
    ArrayWithAddedZeros[Some] = EachNumberWithZeroes
  }
  Result = "";
  for (AddingArray in ArrayWithAddedZeros) {
    Result = add(Result, ArrayWithAddedZeros[AddingArray])
  };
  return Result = Result.replace(/^0+/, "")
}

65.49.68.172 (talk) 05:09, 24 April 2012 (UTC)[reply]

If you really do want arbitrary precision math, you might consider JavaScript BigNumber. However, it seems lately on the computing desk, we're rolling our own reinvented wheels (replete with naïve mistakes that have been resolved by our very smart forebears who authored the standard solutions); so by all means, use your implementation! After a quick glance, I decided that its variable names are too silly for me to follow, but I assume that you'll be able to quickly discover any incorrect implementation details. Nimur (talk) 05:53, 24 April 2012 (UTC)[reply]
Replaced some silly vairables with non-silly variables. 190.60.93.218 (talk) 14:12, 24 April 2012 (UTC)[reply]

comparison between android and ios development

edit

I've just spent more than a day trying to get "hello world" up and running on Android emulator with Eclipse, without success. I've read that iOS is much easier to get started with. Can anyone confirm that it is easy enough, and whether there are any major pitfalls? I'm about going mad with Android, and ready to quit, but I don't have a Mac yet, so I might as well give Android an extra go. I just want to know there's a light at the end of the tunnel, should I decide to quit Android forever. IBE (talk) 05:36, 24 April 2012 (UTC)[reply]

There're over seven-hundred people in irc://irc.freenode.net/android-dev*, and over two-hundred in irc://irc.freenode.net/iphonedev you could speak with in real-time. As the numbers may indicate to you, Android is less expensive and (likely not coincidentally) more popular; I dare say the difficulty in developing for either is largely comparable, however. ¦ Reisio (talk) 19:18, 24 April 2012 (UTC)[reply]
There are lots of tutorials for both Android and iOS. In terms of getting started, Android isn't hard, and there's a lot of online support. If you don't like IRC, you can check a web forum[1][2][3] and this page has more resources[4]. --Colapeninsula (talk) 09:10, 25 April 2012 (UTC)[reply]
Thanks to you both for the suggestions. "Easy" and "hard" are matters of opinion, and having just spent 3 days getting "hello world" running, I would call Android unreasonably hard. I googled my error message, and the suggested solution was to install something I already had. For others who are interested, I finally solved the problem using something I came across more or less by accident: see here. From there, it was easy enough to fix, but it was very hard to find the right site. I had to configure Eclipse via Eclipse->Window->Preferences->Android, and change the path from C:\Users\<my name>\android-sdks to C:\Program Files\Android\android-sdk. The sdk was installed in both places, and Eclipse got the wrong one. I find this highly counterintuitive, and an annoying hurdle for getting "hello world" up and running. You are free to differ. IBE (talk) 09:33, 25 April 2012 (UTC)[reply]

Unnecessary music in a videogame

edit

A well-known game has a room containing nothing special except a room-specific music, so the player is expected just to pass through to the next room, which means s/he's supposed to listen to less than 10 seconds of music, or less. Why did they provide SIX minutes of music instead? Note that it is not played in any other part of the game. --151.75.48.159 (talk) 07:12, 24 April 2012 (UTC)[reply]

My guess is that the musician is a friend of one of the developers, who promised he would play the entire song in the game. But, for whatever reason (didn't go with the game, etc.), they decided to marginalize it by playing it in that one room only. StuRat (talk) 07:16, 24 April 2012 (UTC)[reply]
Can the OP give an example of a situation where music IS necessary in a video game? Most of it annoys the crap out of me. HiLo48 (talk) 08:10, 24 April 2012 (UTC)[reply]
By unnecessary I meant superfluous. --151.75.48.159 (talk) 10:55, 24 April 2012 (UTC)[reply]
Or, the music was supposed to be included elsewhere as well, but due to time constraints/changing requirements, it was left out. A lot of games have content included on the disks that isn't actually used at all, even in the DOS era. 173.68.52.122 (talk) 02:32, 30 April 2012 (UTC)[reply]

Animated GIF frame order

edit

When using the loop option for an animated GIF with 4 frames, it wants to do them in this order:

1,2,3,4
1,2,3,4
1,2,3,4
  .
  .
  .

However, I'd like to get:

1,2,3,4,3,2,
1,2,3,4,3,2,
1,2,3,4,3,2,
  .
  .
  .

Is there any way to get this order, without duplicating frames 2 and 3 as frames 6 and 5 ? I use ImageMagick to do the stitching. I specify the inputs as "frame*", would it work if I gave it "frame1 frame2 frame3 frame4 frame3 frame2" as the inputs ? If so, would the result be any smaller than if I duplicated the frames as frames 5 and 6 and used "frame*" in the input string ? StuRat (talk) 16:03, 24 April 2012 (UTC)[reply]

When you put a * in a command line, you're doing filename globbing. How that really works varies:
  • On unix/linux/bsd/osX globbing is done by the shell (e.g. bash), and the called program is passed a command line with all the filenames already expanded. It's my recollection that POSIX insists filenames be in the prevailing collation order (which means they're probably in alphabetical order for you).
  • On Windows command.com/cmd.exe the filenames aren't globbed by the shell - the program is passed just a * and has to do whatever globbing it wants itself. Imagemagick does, but I can't see a guarantee of collation order.
  • On Windows Powershell I think the globbing is done by the shell; I don't know the ordering.
Assuming collated globbing, if you say frame * you'll get all the frame file names, in sorted order. So just explicitly specifying them is the same as what the globbing generates, but you get to control things and specify an alternate order. -- Finlay McWalterTalk 17:14, 24 April 2012 (UTC)[reply]

Thanks. I did a bit of testing, and I can get it to do what I want with this ImageMagick command:

convert f1.ppm f2.ppm f3.ppm f4.ppm f3.ppm f2.ppm animation.gif

However, the resulting animation is far larger than if I had done:

convert f1.ppm f2.ppm f3.ppm f4.ppm animation.gif

So, apparently it just duplicates the frames, rather than linking to them in the order I specified. Is there any way around this, or is this beyond the capabilities of an animated GIF ? StuRat (talk) 18:05, 24 April 2012 (UTC)[reply]

It is beyond the capabilities as far as I understand it. The format just iterates through frames; it doesn't have a sophisticated frame control system. You can make it specify things like the number of repetitions, and the time between individual frames, but it is going to march from beginning to end no matter what. (And for what it's worth, APNG seems more or less the same in this respect. MNG seems more complicated in its capabilities but I'm having a hard time really seeing what they are; you can do loops within loops but I think they're still just forward moving, so it doesn't change much in this case.) --Mr.98 (talk) 01:08, 26 April 2012 (UTC)[reply]
OK, thanks. Too bad, as going back down from the last frame to the first frame gradually usually makes more sense than jumping directly back. StuRat (talk) 03:44, 26 April 2012 (UTC)[reply]

Problem with external hard drive

edit

A few weeks ago (about early March) I got a 6TB external hard drive and had problems with it. I asked here. I've returned two of them and got replacements. The HD has USB 2, firewire, and eSATA connections. I want to use it with eSATA. The problem is that using the eSATA connection, I can't get more than 2.19TB of files onto it using the eSATA - it starts getting very slow and then it stops and locks up the computer. I've tried it about 20 times over the weeks. I do not have that problem with USB 2, but naturally USB 2 is too slow. The company thinks that the problem is with my computer and suggested trying it on a different computer. I checked around, and I don't have access to another one with eSATA. But since USB 2 works, I decided to get a USB 3 to eSATA adapter, and use the USB 3 connection on the same computer to the eSATA connection on the HD. The USB3/eSATA method works - no problem.

I noticed that if the HD uses 512-byte sectors/clusters, 2^32 of them is 2.199TB - just about the amount where I have the problem with eSATA. Could there be something about my motherboard that causes that problem (I got it new last year)? Could there be a problem with the company's drivers for the eSATA (I have the latest ones installed)? Bubba73 You talkin' to me? 18:54, 24 April 2012 (UTC)[reply]

The symptoms you describe sound very much like what happens to a program when the memory is filled up and paging space must be used. I suspect that eSATA uses a 32 bit index, and when addresses get larger than that it uses some kludge to try to keep working, but one as bad as paging space, unfortunately. I can see a few options:
1) Reformat the HD to use larger sectors/clusters. You'd want them at least 3 times larger, so we should go with the next multiple of 2, and make it 4 times larger, or 2048-bytes per sector/cluster.
2) Continue to use your current workaround.
3) Return that external hard drive, and use 3 hard drives of 2 TB each, instead. This setup might also last longer. StuRat (talk) 19:21, 24 April 2012 (UTC)[reply]
RE: 3) That may well be a good idea for economy and versatility as well. ¦ Reisio (talk) 19:25, 24 April 2012 (UTC)[reply]
Sectors and clusters are not the same thing. You can't change the sector size. I don't know what the problem is here, but your suggestion that some kind of "paging" is going on is silly. -- BenRG (talk) 22:09, 24 April 2012 (UTC)[reply]
That was not my suggestion. I was using that as an analogy, as indicated by the words "like" and "as", to show that some resource was being used up (similar to memory) and thus some kludge was being used in an attempt to keep going (similar to paging space), but that this was working far more slowly (like paging space). I then proposed that the limiting resource, in this case, is indeed 32-bit indexing. StuRat (talk) 16:05, 25 April 2012 (UTC)[reply]


Are you getting the same transfer rate with your USB3 adapter? Less? More? ¦ Reisio (talk) 19:25, 24 April 2012 (UTC)[reply]

Some replies: (1) I tried reformatting to 2048-byte clusters once. I still had the same problem but I'm not positive I was successful in reformatting it that way. (2) If I can't use this drive I'm out about $450. (3) The transfer rates with the USB3/eSATA combination are comparable to the eSATA rate. I was reading from a USB 3 drive and writing to the 6TB drive. With eSATA it was up to 120MB/sec but around 100MB/sec most of the time. With USB3/eSATA combination, it was around 100MB/sec (so close enough). (With USB 2 it was 25MB/sec.) Bubba73 You talkin' to me? 19:51, 24 April 2012 (UTC)[reply]
I selected this drive because it has two 3TB drives in RAID. I have it set to RAID0, but my tests don't indicate that it is any faster than my USB3 external HD in sequential reading. I would have been better off to get two 3TB USB3 drives for less than the 6TB eSATA RAID drive or two 4TB USB3 drives for about the same price! Bubba73 You talkin' to me? 19:56, 24 April 2012 (UTC)[reply]
Yes, I think you might be on the bleeding edge, meaning you are paying higher prices to get the latest technology, which is not yet fully supported. Incidentally, why do you need 6 TB ? Do you want to store hundreds of movies on there ? StuRat (talk) 21:10, 24 April 2012 (UTC)[reply]
Changing to a larger cluster size doesn't affect the number of sectors. You should use clusters of 4K or larger because many newer drives actually have 4K sectors but pretend to have 512-byte sectors for backward compatibility. If you use 2K clusters you will end up with a lot of half-sector writes, which is slow. -- BenRG (talk) 22:09, 24 April 2012 (UTC)[reply]
It is for a database that is currently 2.7TB (and is on a 3TB drive) and will be growing to around 5TB. Right now it is all one big file on the 3TB drive. But I realized that doesn't really have to be in one file or all on one drive. I first tried to copy it as one file to the 6TB drive with Windows copy, but it failed. The second try failed. I thought it might not like files that big, so I decided to break the file into 500GB parts and rewrite the program that uses the data. That failed in the same way. Then I tried breaking it into 50GB parts and analyze what is happening with the transfer speed, which is how I discovered the problem around 2.19TB. Bubba73 You talkin' to me? 23:33, 24 April 2012 (UTC)[reply]
To give you an idea of the speed, with USB2 (and the USB3/eSATA combination), performance varied but it never got terrible. With eSATA, just writing to the disk from memory (i.e not copying from another HD), write speed started at 100 to 120 MB/s. When it got somewhere over 2TB, it slowed to under 4MB/second, and after doing that for a while, it would lock up the computer, requiring a hard reboot. Bubba73 You talkin' to me? 03:00, 26 April 2012 (UTC)[reply]
How bad is the performance with the USB3/eSATA combo ? You might want to use USB3 alone until you fill it to that point, then switch to the combo. StuRat (talk) 14:39, 26 April 2012 (UTC)[reply]
The USB2 performance is about 25MB/sec, which is not good enough (5TB would take 55 hours - way to slow). I can't use USB3 alone because the 6TB HD has USB2, eSATA (and Firewire). The USB3/eSATA performance is about the same as the eSATA performance, and it doesn't encounter the problem, so I'm sticking with that. Bubba73 You talkin' to me? 15:14, 26 April 2012 (UTC)[reply]
OK, I guess that's the best you can do with your current configuration. StuRat (talk) 15:22, 26 April 2012 (UTC)[reply]

Insight about recovery disk

edit

I am new to the concept of recovery disk of the last Windows versions. The last time I installed Windows, it was from a single CD, which was shipped by Microsoft. So, I am a little bit insecure about the way to deal with it. I need some basic fact-checking and questioning:

  1. when I get a new laptop, there would be an image of Windows that has to be installed on a different partition right?
  2. I have to make a back-up of this image into a DVD. But how many DVDs I'll need? And why not a pen-drive?
  3. this image can only be installed in the computer where it was shipped. But what about if I buy a new HDD, how can I install this Windows image? Or, can I install this Windows image everywhere? — Preceding unsigned comment added by 88.8.68.89 (talk) 20:31, 24 April 2012 (UTC)[reply]
I hope you don't mind, I've tweaked your post to use a numbered list, which will answering your questions slightly easier -- Finlay McWalterTalk 20:52, 24 April 2012 (UTC) [reply]
OK. 20:54, 24 April 2012 (UTC)
  1. Yes, that's almost always the case nowadays.
  2. Yes. How many varies (you're also backing up all the additional stuff they install, like trialware of anti-virus and office programs)
  3. Really you can only reinstall on this machine (and others of the same model from the same manufacturer).
Some companies will sell you a recovery DVD (so you don't have to burn one). -- Finlay McWalterTalk 20:56, 24 April 2012 (UTC)[reply]
For 2, the number of disks might be between 2 and 5. I've not seen one that offered a pen drive, but they may do that now. In practice these restore disks often use a rather crappy OEM version of Norton Ghost. Personally, for problems like this, I'd instead make an image myself with something like Clonezilla. -- Finlay McWalterTalk 20:58, 24 April 2012 (UTC)[reply]
As to part of 3 "what about if I buy a new HDD" (and you could also ask "what if my hard disk breaks and I replace it") - I think the first restore disk is an El Torito bootable disk. -- Finlay McWalterTalk 21:02, 24 April 2012 (UTC)[reply]
Thanks. 88.8.68.89 (talk) 21:09, 24 April 2012 (UTC)[reply]
Re the pen drive (depending on software) it's generally do-able - in most cases you just save to the pen drive directory instead of the DVD directory. However you need to have "boot from USB" enabled and possible - this is a bios setting. If this is what you want to do it is actually quite easy and not painful, provided your computer supports this.Oranjblud (talk) 01:09, 27 April 2012 (UTC)[reply]