"A little progress everyday adds up to big results"

Saturday 30 June 2012

Comparing floating point numbers in programming languages

                    Some times, while programming, we might need to handle floating point numbers. In such cases, we cannot compare them simply by giving '==' operator, because, we cannot expect the numbers to be perfectly equal, if the number of values beyond the decimal point goes unlimited. In such cases, we can follow these steps.

(Assuming we need the floating point numbers to be equal for 4 digit precision)
For C/C++:
#define PRECISION_DIGITS 4
#define DELTA pow(10, - PRECISION_DIGITS)

For Java:
final int PRECISION_DIGITS = 4;
final float DELTA = Math.pow(10, - PRECISION_DIGITS);

and in the program, you can compare like this
if ( abs ( value1 - value 2 ) < DELTA ) // For Java change abs to Math.abs
{
       // Statements for value1 == value2
}
else
{
      // Statements for value1 != value2
}

More references regarding the floating point comparison is available in this site.

Tuesday 26 June 2012

The power of NDK in Android

                     While developing android applications, sometimes, one might want to perform CPU intensive operations like huge number of calculations. In such cases, the time taken for performing those operations might be so high, so that the user gets frustrated. Of-course, one can run such operations as a Service ( background task ) and intimate the user on completion via notification; but, there is a better alternative in Android, called Native Devleopment Kit ( NDK ), which allows development from C/C++ instead from Java.

                       It is simply the equivalent of Java Native Interface ( JNI ) in Java. This is nothing but, calling C/C++ functions from Java. If one has a very basic knowledge of JNI, then it's not at all a matter for him/her to develop application in NDK. I faced this situation once, when I developed Speaker Recognizer application for android as a part of my internship at IIIT, Hyderabad. I had written the entire code in Java and the code executed nearly for about 40 seconds on a device with operational frequency 600 MHz. When I reported this to my project guide, Dr. Kishore S. Prahallad, he suggested me NDK.

                      I thought that C/C++ would be some 2 or 3 times faster than Java. But, to my surprise, my code executed in just 4 seconds on the same device, which is almost 10 times faster. I was wondered and realized that C and C++ are nearly 10 times faster than Java on Android devices. So, if you want to perform CPU intensive operations on android, I suggest NDK. The entire tutorial is available at this site.

Functional testing of your mobile

                       Almost all possess at least one mobile phone now-a-days. Sometimes, some of the features in the mobile might not be working. In such cases, you yourself can test what has went wrong by following some simple steps as given below.

1. Bring your mobile to the home screen ( Unlock if necessary )
2. Press right arrow key once
3. Press * once
4. Press left arrow key twice
5. Press * once
6. Press left arrow once
7. Press * once
8. Now, you can see a menu. Select a one which has 'Testing' or 'Test' term
9. You can now, select the functionality that you want to test.

Note:
1. Perform these operations at your own risk. You can use 'back' button to return back.
2. The key order might change on some mobiles.

Sunday 10 June 2012

My visit to Birla Temple and Birla Planetarium

                          It was too boring for me at IIIT, Hyderabad when I went for an internship during my second year summer vacation. My mom was insisting me to go somewhere out, especially to the Birla Temple. So, I have decided to go on a Sunday.

Preparations:
                     On June 9th, with the help of google maps, I found out the guidelines for going to Birla Temple from IIIT and also found that Birla Planetarium is very close to the temple. I have decided to go there the next day ( Sunday, 10th June, 2012 ).

Starting of my journey:
                         After asking the location of the bus stop to one of the securities of IIIT, I went to the stop. A bus came in 10 minutes. With a little hesitation whether or not the bus will go to Birla Temple bus stop, I boarded and asked ( while standing in the steps ) a person ( a policeman ), who was sitting in the first row of the bus, whether the bus will go to Birla temple. He replied in positive and asked me to sit next to him in action. I did so.

Bus ticket:
                        That policeman asked me something in Telugu. I said that I don't know Telugu and Hindi. He asked me where actually I am going, in English. I said that I am going to Birla Temple. When the conductor came and asked for the ticket, that policeman himself told "1 Birla Temple" and I gave a 10 rupees note to the conductor. When the conductor asked for 2 more rupees ( as the ticket was 12 rupees ), the policeman translated it for me, though I understood the words of the conductor. The policeman asked the conductor ( in Telugu ) to intimate me on the bus reaching Birla Temple stop.

On the way:
                        On the way I could see a vehicle sweeping the road and the other one pouring water to the plants in the median, at 7:30 am. The policeman informed me that he is going to alight and added that my stopping is 5 stops next. He also informed the driver to intimate me on reaching Birla Temple and alighted the bus. On reaching the stop, the driver and the conductor intimated me and I alighted.

At Birla Temple:
                    Finally, after asking the route from 3 people, I reached Birla Temple. There, the temple is wonderful. The whole building is made up of crystals. After admiring at the architecture, I entered and worshiped Lord Venkateshwara. As soon as I came out after my prayer, I could see a view of Hyderabad as if it's seen from a 6 or 7 storied building. Unfortunately, we are not allowed to take mobiles or cameras inside. I also saw a lake with some fountains and the morning breeze ( around 8 am ), pleased me. Though, I know that the temple's beauty is much more reflected during the night time, I couldn't stay that long. Here are some pictures of Birla Mandir obtained from the internet.


At Birla Planetarium:
                       After returning back from the temple, I had my breakfast in a nearby hotel and went to the Birla Planetarium which is next to the temple. But, the ticket counter to enter the planetarium had not been opened at 9:45. Many people, including school students, were curiously waiting for the counter to open. Everyday there are shows ( in Telugu, Hindi and English ) at the planetarium, among which the shows in English are at 11:30 am, 4 pm and 6 pm. A science museum is also located inside the planetarium itself. After opening of the counter around 10:45 am, I got the tickets for both the planetarium show ( at 11:30 ) and for the science museum.

Science museum:
                      I remember, when I was a kid, I have been to a Science museum at Bangalore. With full of curiosities, I entered the museum at 11 am. There were many instruments each depicting a science experiment. I just had a overview of what are available in the museum and the time was 11:33. I rushed to the planetarium. I was asked to switch off my mobile and I did it. The show had started. But, then, some other people who came late and I were taken inside a dark room. Later they took into the theater where the show was held. Due to the darkness, I couldn't move and I was standing still. I could see 2 small dots ( as stars ) in the side wall. After some time, I was guided and asked to sit in a vacant place.

A visit to the Solar System:
                        After sitting and leaning back, I could see a number of stars and objects in the ceiling of the doom shaped theater. Starting from Mercury till Neptune, each and every planet were described in detail along with some videos and an illusion of what one would see, if he/she is landing in that particular planet. Being a lover of Space Science since my childhood, I enjoyed the journey to the Solar System. After a 45 minute travel in the solar system, I went back to the Science Museum.

Pictures of Birla Planetarium





Back to museum:
                         Some of the experiments which I liked were, the depiction of Pythagoras theorem, optical illusion experiments, density and refractive index variation of water with change in temperature, periscope to see the happenings at the 1st floor from the ground floor, etc. Some people were taking notes of whatever they see. Simply saying, Science Museum is place for enjoyment for kids, knowledge zone for students and entertainment zone for others. Later, I also happened to see a skeleton of a Dinosaur. Here are some pictures of Birla Science Museum.



Wednesday 6 June 2012

Vignesh Jagadeesan

                     Vignesh Jagadeesan is one of my best friends. Here I am going to tell you, how we became friends.

Meeting:
                     During the first year of my engineering, I used to go to college by bus. Vignesh also used to come to college by bus. We had seen each other. But, hadn't spoken to each other. Vignesh had achieved a lot by presenting papers, posters and also by winning in almost all of his presentations and competitions that he participated in, during his first year of engineering itself! He maintains a social relationship with everyone he meets. I used to see him noting down the unknown terms from the newspaper in the college library.

First speaking:
                      It was the last day of our first semester theory examinations. It was 'Engineering Graphics' exam where we were supposed to draw some shapes using a template. It was held batch-wise and after my batch completed the exam, Vignesh had his exam. He forgot to bring his template. So, he asked mine. I gave and even before I ask his name and department, he introduced himself to be 'J.Vignesh from CSE - C section'. He told that if I am not available, he would give the template the next semester after 10 days of semester holidays. I accepted.

Template:
                  As his face showed that he is so sincere and is a very responsible person, he returned back the template on the very first day of the college reopening, by coming to my class! After some days, when I went to his class, everybody in the class started shouting. I was shocked and didn't know the reason. Then I came to know that they are making fun of Vignesh and me, as we look the same.

A wonder:
                     Whoever sees us both for the first time, used to ask us whether we are brothers. I had written a modified version of 10 Thirukkurals, which I had shown to the first year dean, Mr. Karunakaran. He had asked Vignesh, are you the boy who wrote those Thirukkurals. I came to know this around the end of 2nd year ( on March 10th ). The wonder is that, both our characters as well as appearance matches almost exactly!

First presentations:
                 No sooner we became friends, we started doing presentations together from the third semester. The first paper presentation that we did was in Sri Venkateswara College of Engineering, Chennai and the first project presentation was in Thiyagaraja College of Engineering, Madhurai. But, before that, we both attended In-plant training at BSNL, Salem.

Teachers' comment:
                      Vignesh's class councellor, Ms. Theetchanya, said when she met me for the first time,  "அதே தலை, அதே முடி, அதே மண்டை" and dean of CSE, Dr. Usha mam used to make fun of us, by saying "Suresh... Ramesh..." ( because, it was a famous 'Diary milk' advertisement at that time ).

Feeling proud:
                     If I hadn't been a friend of Vignesh, I might not be able to undergo a fellowship, which is a turning point in everyones life! I wish him all success in his life. I am very proud to be his friend and trust that our friendship will never end!