Categories
discuss

javascript large integer round because precision? (why?)

If you do

for(var i = 0; i < 30; i++){console.log(i + " == " + 78764357878563800 + " ? ");console.log((78764357878563790+i) == 78764357878563800);}

You start comparing values from 78764357878563790 to 78764357878563790+29, so… like you see if you run it, you get true from i = 8 to 24.

So I don’t know if I don’t get it, but isn’t supposed to exist the maxint (which I dont know) and a maxint-1??? and then max be different than maxint-1?

I suppose this is precision like floating numbers… but that isn’t supposed to only hit floating numbers and for example, number+1 always gives the successor? (so in the example above, if i = 78764357878563790 and add i++, then you enter an infinite loop.

I know before hand that this type of spacing between numbers exist for floating points, but never hit a case where also the integers cant represent i+1 and i-1 (I always thinked that unsigned maxint + 1 would carry and give 0).

Any suguestions in:

  • which is the max number and what is the anterior number in js.
  • how to handle or know when this behaviour for integers will start happening.
  • how to handle this large numbers and more big than this would be nice.

Answer

There are no integers in Javascript.

Numbers are double precision floating point, which gives you a precision of 15-16 digits. This is consistent with your results.

Categories
discuss

Android Emulator Keyboard not displaying

Just installed the android sdk on my macbook pro. I created a virtual device, allotted 50mb worth of memory in android 3.0. I ran the emulator, and Android_ displays on the left, but the keyboard interface does not display on the right. I have hw.keyboard.lid enabled. Not sure if that has anything to do with it.

Answer

Press CTRL+F11 or num pad 7 to enable an onscreen keyboard within the OS. I don’t think the 3.0 emulator has an equivalent keyboard interface the way the others do.

Categories
discuss

How to write/debug Android.mk for NDK static library?

I’m trying to build a static library using the latest Android NDK (r5) and I’m not having any luck. I’ve been able to build and run the samples (for example, HelloJni) without any issues but starting a new project from ‘scratch’ has been a different story.

For this experiment, I’m trying to build libpng. My folder structure looks like this:

root
|
+--- jni
      |
      +---- Android.mk ( one line: "include $(call all-subdir-makefiles)" )
      |
      +---- png
             |
             +---- Android.mk ( see below )
             |
             +---- { a bunch of .c and .h files )

So I have two Android.mks. One for building all subprojects and one for the libpng subproject. root/jni/png/Android.mk looks like this:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := png
MODULE_PATH := $LOCAL_PATH
LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/*.c)
LOCAL_C_INCLUDES := $(wildcard $(LOCAL_PATH)/*.h)

LOCAL_INTERMEDIATE_TARGETS += junk
junk:
    echo $(LOCAL_SRC_FILES)

include $(BUILD_STATIC_LIBRARY)

This build setup seems to do nothing (ie running ndk-build from the root folder does nothing, even after an ndk-build clean). A verbose run (ndk-build V=1) shows some rm -f calls (deleting non-existent folders) but nothing related to the project or subproject.

I’m pretty interested in why this build script is failing but the process should have been trivial so I’m sure its nothing terribly interesting. I’m far more interested in how I could start to attack build bugs on my own. The echo call in the script above is never hit — I have no idea how to determine what values are or why it skips the subproject. Has anyone found a way to know what the build system is trying to do?

I’d also be interested in knowing if there are docs for these tools or if its just the handful of text files in the NDK’s docs folder? I’ve been trying to resolve this by copying pieces of random Android.mk’s I’ve found from googling around but only the few commands used in the simple NDK samples appear to be documented, so the experience has actually just raised new questions.

Answer

I’d recommend getting rid of MODULE_PATH and not trying to use the wildcard: I haven’t really seen that work right.

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := png
LOCAL_SRC_FILES := pngget.c pngread.c pngrutil.c pngtrans.c pngwtran.c png.c pngmem.c pngrio.c pngset.c pngwio.c pngwutil.c pngerror.c pngpread.c pngrtran.c pngwrite.c
LOCAL_C_INCLUDES := png.h pngconf.h pngpriv.h

include $(BUILD_STATIC_LIBRARY)

Also, there’s some serious path magic I haven’t fully deciphered: somehow Eclipse does the right thing, but getting it to jump through the proper hoops from the command line is still hit or miss for me.

EDIT: so was moderately interested in figuring this out, as its been a while since I played with the NDK. When I use the original file it didn’t compile, but when I placed the png source code in the directory jni and then use this Android.mk file:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := png
LOCAL_SRC_FILES := pngget.c pngread.c pngrutil.c pngtrans.c pngwtran.c png.c pngmem.c pngrio.c pngset.c pngwio.c pngwutil.c pngerror.c pngpread.c pngrtran.c pngwrite.c
LOCAL_C_INCLUDES := png.h pngconf.h pngpriv.h

include $(BUILD_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := png2
LOCAL_STATIC_LIBRARIES := png

include $(BUILD_SHARED_LIBRARY)

it built both the libpng.a and libpng2.so in the obj/local/armeabi folder. I’m guessing it simply won’t build an static library if there is no dependency.

Categories
discuss

Extract substring out of a string using Javascript

All,

I have the following html as a string in javascript. I need to extract the string in “value”, split by the specified delimeter “|” and put in two variables.

var html = '<div><input name="radBtn" class="radClass" style="margin:auto;" 
       onclick="doSomething();"
       value="Apples|4567" type="radio">
</div>';

Required output is two variables having the following values:

fruitName = Apples
fruitNumber = 4567

Note: There can be many radio buttons with the same name.

Answer

If you can assume that your HTML is always going to be simple (i.e. only one value attribute, and nothing else that looks like a value attribute), then you can do something like this:

var fruit = html.match(/value="(.*?)|(.*?)"/);
if (fruit) {
    fruitName = fruit[1];
    fruitValue = fruit[2];
}
Categories
discuss

Whats the most used cross-platform Mobile Application Development Framework today?

I’m like many others here, giving their first steps in the mobile world an not knowing where to start from…

Well, I’ve seen a few posts here about mobile development frameworks or sdk’s, but all of them are directed to specific purposes, like web clients, widgets, html development, etc…

What I’m really wondering is, amongst all the choices currently in the market, like PhoneGap, Rho, or Corona, and all the others, what is the most used MDF for general cross platform mobile development.

Obviously, I’m not looking to get the perfect platform for every purpose, but at least know your opinions and what frameworks are you using now, if any…

Thanks for the help!

Answer

I would highly recommend the Corona SDK.

Not only is it the easiest to learn (Lua is one of the most simple, and powerful scripting languages I’ve ever seen), but it also provides an extremely wide range of functionality in comparison with other third-party SDK’s.

Development time is drastically reduced using Corona because most things only take a few lines of code to implement. There are also several monetization options available to you using the Corona platform.

Not only that, but it produces NATIVE apps, and allows you to re-use the same code to output for both iOS, Android, Nook, and obviously other platforms in the future. And that’s the way cross platform should be in my opinion.

Performance is amazing, as well. It’s strange because although Corona is the simplest to use and the easiest to learn, it’s probably the most powerful among other options in terms of on-device performance, and the closest you’ll get to going native without going native at all.

Another great thing is, you don’t even have to touch Xcode or any of Android’s tools–apart from installing them. With a minor exception of Android, where you’ll need to use ADB to install the apk to your device.

HUGE BONUS: Support is excellent. The founders are very transparent, easy to get ahold of, and communication is awesome.

You can read two separate reviews I did on the Corona SDK, both were written six months apart:

Corona SDK Review

http://jonbeebe.net/post/1119939987/corona-sdk-review

Corona SDK: Revisited:

http://jonbeebe.net/post/2726165170/corona-sdk-revisited

You can do a search on my blog on ‘Ted Patrick’ to find an article written by Barne’s & Noble’s Chief Developer Evangelist for NOOK where he explains Corona’s internal infrastructure and how well it works. I would post the link here, but I can only post two links per stackoverflow’s policies.

Hope that helps!

Source: stackoverflow
Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Privacy Policy, and Copyright Policy. Content is available under CC BY-SA 3.0 unless otherwise noted. The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 © No Copyrights, All Questions are retrived from public domain..