Saturday, March 03, 2012

Diversions in C Minor

Last year we saw the passing of Dennis Ritchie. I was one of the lucky students who used the K&R book as a text book in college. Actually it's pretty amazing that the text books for CS first years were K&R and The Mythical Man-Month. There was pretty much no excuse for me to F up after being taught from those two books. The untimely passing of Ritchie made me recollect that I never really finished K&R. My professor used many of the chapters as reference material, and of course at some point I figured that I already knew everything so well that I didn't need no stinkin' book. So I decided then that I would re-read the book including all of its problems.

Of course I didn't start re-reading K&R right then as I should have. But I did get around to it recently. The very first problem in chapter two asked the reader to calculate the minimum signed chars, shorts, ints, and longs, and the maximum of those plus their unsigned cousins. These are all very straightforward things to calculate for anyone with an understanding of modular arithmetic. The book then mentions a more challenging problem: calculating minimum and maximum floats. No problemo I thought: Obviously that doesn't work, or this would be a pretty boring blog post. Here's where the awesome comes in. On my MacBook Air, this prints 1.175494e-38 for FLT_MIN but the second line prints 1.401298e-45 for the "calculated" minimum float. That's right it calculates a value that is smaller than FLT_MIN.

Experienced C developers will surely recognize what is going on here but I was flummoxed. It was only upon looking at some of the other constants defined in float.h that I started to figure out what was going on. In particular I noticed that on my MBA, FLT_MIN * FLT_EPS = 1.401298e-45. FLT_EPS is "float epsilon" and is defined as the smallest x for which 1+x != x. This is sort of the standard error on the system, i.e. any calculation could be off by a factor of FLT_EPS. I decided to calculate this in my program and then to also use it to calculate FLT_MAX: The FLT_MAX calculation takes a long time, since it uses such a small increment. I'm sure a bigger increment could be used to speed it up.


Unknown said...

We are a third party technical support service. Avast Customer Support is here to help you out with the whole procedure to Download Avast Antivirus online, We not only fix your Avast Support related issues but will guide with how to get started with your new Avast product once it gets installed successfully.We at Avast Tech Support provides service to protect your PC from potential online threats and external attacks like viruses, Trojans, malwares, spywares and phishing scams. And Avast Refund. Call on our Avast Phone Number.

Gmail Customer service is a third party technical support service for Gmail users when they face any technical issue or error in their Gmail account. Our Gmail Customer Support team solves issues like forgot Gmail account password, Gmail configuration or Sync issues, recover deleted emails and many more. Toll Free number (800) 986-9271
How you install or reinstall Office 365 or Office 2016 depends on whether your Office product is part of an Office for home or Office for business plan. If you're not sure what you have, see what office com setup products are included in each plan and then follow the steps for your product. The steps below also apply if you're installing a single, stand-alone Office application such as Access 2016 or Visio 2016. Need Help with office setup Enter Product Key? Call 1-800-000-0000 Toll Free
Norton Tech Support is a third party service provider and not in any way associated with Norton or any of its partner companies. We offer support for Norton products and sell subscription based additional warranty on computer and other peripheral devices. Call our Toll Free number 1 855 966 3855
Other Services
Norton Toll Free , Office-Setup ,

Unknown said...


Petter Marry said...

Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog.
Really very informative post you shared here. Kindly keep blogging.
If anyone wants to become a Front end developer learn from Javascript Online Training from India .
or learn thru JavaScript Online Training from India.
Nowadays JavaScript has tons of job opportunities on various vertical industry. ES6 Training in Chennai

Aishwarya said...

It's like you read my mind! You seem to know a lot about this, like you wrote the book in it or something. I think that you can do with some pics to drive the message home a little bit, but instead of that, this is fantastic blog. A great read. I will definitely be back.
HRMS Software In India
Human Resource Management Software
HRMS Software Chennai
HR Software In Chennai
HR Management Software In India
HRMS Chennai

Strikethrough Text said...

Very useful article. This is full of information I can't wait to dig deep and start utilising the useful resource given by you. This is probably the best blog I came across today. I Just want to add that if anyone want to Learn how to Strikethrough Text in Word, Excel and PowerPoint and see the other advanced text settings available then nuts and bolts speed training is best choice for them.

meldaresearch said...

The ultimate goal of e-commerce assignment writing services is to provide E-commerce Essay Writing Services and e-commerce research paper services since most business assignment writing service students lack time to complete their custom e-commerce homework writing services.

BestTrainingKolkata said...

I must abide that you are highly trained at influential writing as I am highly convinced to share your views. I am extremely amazed by your excellent writing abilities. Please keep up your good work!
SAP training in Kolkata
SAP course in kolkata
SAP training institute in Kolkata

BestTrainingMumbai said...

It is really great to know you being a responsible writer did take care about the information you have provided in this article. This is elegantly prepared and well-written in my opinion.
SAP training in Mumbai
SAP course in Mumbai
SAP training institute Mumbai

youtubecomactivate said...

Nice Post.
As we realize that YouTube is the best stage that offers a wide assortment of shows. You can find parcels something on YouTube extending from activity and diversion to family charming instructional substance material. You will be essentially signing in to your account visit YouTube Com Activate and enter a digit code which you have. Viewing a YouTube show for your huge TV show genuinely makes the appreciate tons better when in contrast with a PC or PC show.
Read more…

Karl N. Wilson said...

There are also a good number of people out there who have tried out different methods that will enable them to earn money without having to spend a penny. You can get cheap Instagram followers from these people by providing the right amount of quality content to your buy instagram followers australia

Karl N. Wilson said...

If that's your reason for buy tiktok likes, then by all means, you don't need to pay anything at all. But if you're just looking to watch videos for personal entertainment, then you'll probably need to consider buying a few of them.

Karl N. Wilson said...

Buy Instagram Likes for your business by buy instagram likes uk that will increase your company's engagement numbers. Buying likes on Instagram is a great metric to gauge your effectiveness in your niche. Many people go to Instagram to look at other people's photos and stories. You can target your market to get them to buy your product by offering them a way to purchase these likes.

Online Astrologer said...

Thanks for shearing such a nice article.your writing skill are impressive.Free astrology predictions from top astrologers in India as per your Birth Chart. astrology Prediction life report utilizes your birth chart to see what your future life looks like. The birth chart can reveal so many things about you,Talk to astrologer on call or chat, and get the benefits of free astrology services and products with more than 30 years of experiences astrologer online.

Talk To Astrologer

Free astrology predictions by date of birth


Aaj-ka Rashifal

jordan said...

Thank you for sharing such a nice blog.Astroswamig is the famous online astrology prediction you can talk to best astrologer of India.and you know your horoscope and kundali.

Gemini horoscope 2021
Taurus Horoscope 2021
Aries Horoscope 2021
Talk To Astrologer
Aaj ka Rashifal
Online Astrologer

@dskastrology said...

Thank you for sharing beautiful content. In case you want to read article in hindi. Then visit below link
DsK Astrology - Most Authentic Website for online astrology services & products
DsK Astrology - Whatsapp Services
DsK Astrology - Talk to Good Astrologer

DsK Astrology said...

Thank you for sharing beautiful content. In case you want to read article in hindi. Then visit below link
DsK Astrology - Most Authentic Website for online astrology services & products
DsK Astrology - Whatsapp Services
DsK Astrology - Talk to Good Astrologer

DsK Astrology said...

Thank you for sharing beautiful content. In case you want to read article in hindi. Then visit below link
DsK Astrology - Most Authentic Website for online astrology services & products
DsK Astrology - Whatsapp Services
DsK Astrology - Talk to Good Astrologer

venkat said...

this is good article
internship request letter | Internship completion letter | internship companies | internship resume objective | internship application letter | Internship with training | internship email | internship experience | What internship means | Internship acknowledgement