dijous, 15 de maig del 2014

Concurso de apps InnovaApps+




El banco BBVA en colaboración con Google acaba de lanzar el concurso InnovaApps  (http://www.bbvaopen4u.com/innovaapps/es) 

Si alguien tiene una aplicación terminada puede presentarla al concurso. La única condición es que se utilizen API's públicas de Google (por ejemplo el API Google Places).

Es una iniciativa conjunta de BBVA y Google, cuyo objetivo es el fomento del espíritu innovador en las soluciones de productividad accesibles para todas las empresas, especialmente la comunidad de pymes y startups.

Las aplicaciones que se desarrollen y presenten a InnovaApps+ deben estar bajo licencia Open Source (basado en el modelo de licencia Apache, versión 2.0). 

divendres, 2 de maig del 2014

Objective-C strings




As you know a common way to create strings is using the literal @"Some String" syntax, for instance:

Why is the reason of the @ sign in front of "Porsche"?
Objective-C is like two worlds in one. You can write, even in the same program, Objective-C and C code. 
In C language you can write a String literal this way:
char *amessage = "This is a string literal."; 
For this reason when you write a NSString literal you have to put the @ sign before the string. It's the way to say to the compiler that it is a NSString and not a C language string.
  
Of course, when writing iOS programs it is better to use NSStrings. C-language strings don't have support for Unicode, so you can't use accents or other punctuations signs.

dijous, 1 de maig del 2014

When it is advisable to use NSDecimalNumber instead of double?


Yesterday, a friend shared with me a problem using double. He was writing a Calculator app,  and he run into this incorrect result:
123456789123456.78 * 1 = 123456789123456.8


Here is why.
NSExpression uses internally the C-based primitive double. Your example can be written as:
double a = 123456789123456.78;
double b = 1.0;
NSLog (@"Result  %@ ", [NSNumber numberWithDouble: a*b]); // 123456789123456.8 
Why the result is 123456789123456.8 instead of 123456789123456.78? The primitive type double uses the IEEE-754 double precision format (http://en.wikipedia.org/wiki/Double-precision_floating-point_format), also known as Bynary64 because uses 64 bits to store the number. Storing a decimal number in a binary format has a number of disadvantages. There is a inherent rounding error that depends of the magnitude of the number.
Between 2 ^52=4,503,599,627,370,496 and 2^53=9,007,199,254,740,992 the representable numbers are exactly the integers. So:
double a = 4503599627370496.6;
double b = 1.0;
NSLog (@"Result  %@ ", [NSNumber numberWithDouble: a*b]); //4503599627370497 
Between 2^53 =9007199254740993to 2^54, everything is multiplied by 2, so the representable numbers are the even ones. So:
double a = 9007199254740993;
double b = 1.0;
NSLog (@"Result  %@ ", [NSNumber numberWithDouble: a*b]); //9007199254740992 
Conversely, for the previous range from 2^51 to 2^52, the spacing is 0.5, etc.
In your case, the number 123456789123456 is in the interval 2^46 - 2^47 and the rounding error is 1 / 64 = 0.015625.
With 64 bits you can work only with a maximum of 15-17 decimal digits, and you'll get rounding errors in all the range.
The solution? You can use NSDecimalNumber that uses decimal arithmetic( Java has BigDecimal )
NSDecimalNumber *decimaNumber = [NSDecimalNumber decimalNumberWithString:  @"4503599627370496.11"];
NSDecimalNumber *decimaNumber2 = [NSDecimalNumber decimalNumberWithString:  @"1"];
NSLog(@"    %@",[decimaNumber decimalNumberByMultiplyingBy:decimaNumber2]);  //4503599627370496.11