Saturday, January 21, 2006

Floating Point Anamoly

Source:YPK "Test Your C Skills" Ch-4 "Floating Point Issues" 1st question

main()
{
float a=0.7;
if(a <0.7) a="="b" href="http://docs.sun.com/source/806-3568/ncg_goldberg.html">IEEE
and
Why this anamoly

One good practice is

use something like
#include <math.h>

if(fabs(a - b) <= epsilon * fabs(a))

for some suitably-chosen degree of closeness epsilon (as long as a is nonzero!).


Is a[i] = i++; valid?

This is a very basic question, but many intersting concepts emerge out of it.

Answer is "Behaviour is Undefined".A compiler may do anything it likes when faced with undefined behavior (and, within limits, with implementation-defined and unspecified behavior), including doing what you expect.

Briefly: implementation-defined means that an implementation must choose some behavior and document it. Unspecified means that an implementation should choose some behavior, but need not document it. Undefined means that absolutely anything might happen. In no case does the Standard impose requirements; in the first two cases it occasionally suggests (and may require a choice from among) a small set of likely behaviors.

The concept of sequence point can be used to base a discussion on
A sequence point is a point in time (at the end of the evaluation of a full expression, or at the ||, &&, ?:, or comma operators, or just before a function call) at which the dust has settled and all side effects are guaranteed to be complete.The ANSI/ISO C Standard states that
"Between the previous and next sequence point an object shall have its stored value modified at most once by the evaluation of an expression. Furthermore, the prior value shall be accessed only to determine the value to be stored."

The second sentence can be difficult to understand. It says that if an object is written to within a full expression, any and all accesses to it within the same expression must be for the purposes of computing the value to be written. This rule effectively constrains legal expressions to those in which the accesses demonstrably precede the modification(as above).

Monday, January 09, 2006

cURL -- A tool limited by imagination

A stock ticker is a piece of code which keeps you updated with the latest(as and when) stock quotations of various companies at the stock exchange. Technically to build this one needs the following tools --

  1. XML
  2. RSS
  3. cURL
  4. sed,awk,grep and simple shell scripting knowledge.

1. XML
Need to know just this concepts elements.

2. RSS (Really Simple Syndicate) -- it is really simple.
As I understand this, there is a link like "http://www.xanadb.com/ticker/YHOO" which provides RSS feed for stocks(YHOO- for yahoo, MSFT-microsoft).
Now observe the xml format carefully. All rss feeds essentially have these 3 elements
title,descrption,link.
An RSS reader is one which makes sense of this rss feed.

So to build the stock ticker here is the design
a) Get the contents of "http://www.xanadb.com/ticker/YHOO" in a variable.
b) Just find the “title” tag. Trash the rest.
c) Find the number and thats it.

3. cURL

Now to achieve step (a) mentioned above we have to use a tool which gets us the contents of the page in a variable or a file.

cURL is shipped freely with most of the Linux installations.

Catch hold of one and execute this

curl "http://www.xanadb.com/ticker/YHOO"

Now go through the manual in case you are using proxies, SSL protected site, etc etc etc.

Now the power is all yours. Just think all the stuff possible with this tool and have i told you this. Its a MIT product.

4. sed,grep and other scripting techniques

Here after its child's play and the scripting skills.

curl "http://www.xanadb.com/ticker/YHOO" | grep title | sed s/title//g

I havent tried the above on a machine , but hope you got an idea as to how the attempt is being made to get the stock quote.

Conclusion

No matter how hard web designers may try to force you to surf their sites interactively, there will always be free tools to help automate the process, thus enriching our overall Net experience.
A deliberate attempt has been made only to answer the "How" part of the tools and not the "What" part of them, as they are available in the links suggested.

Next in Line

PODCAST -- what the hell is this

cant use html tags

After writing the article , I just realized that some html tags (like title, link etc in the exact syntax) cant be used in the article. So I could not use the tags correctly.