summaryrefslogtreecommitdiff
path: root/Practical_C_Programming/Chapter_16_1.ipynb
blob: 505718fd049b2998763cac4eb89c1db2a3c0c920 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
{
 "metadata": {
  "name": "",
  "signature": "sha256:8846db95d13f18ddbaba03cb28aa141be8268e397ec14735e02a0f66209b0b25"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 16: Floating point"
     ]
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 16.1, Page number: 322"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variable declaration\n",
      "number1 = 1.0\n",
      "number2 = 1.0\n",
      "counter = 0\n",
      "\n",
      "# Calculation and result\n",
      "while (number1 + number2 != number1) :\n",
      "   counter += 1\n",
      "   number2 = number2 / 10.0\n",
      "\n",
      "print ('%2d digits accuracy in calculations\\n' % counter)\n",
      "\n",
      "\n",
      "number2 = 1.0\n",
      "counter = 0\n",
      "\n",
      "result = number1 + number2\n",
      "counter += 1\n",
      "number2 = number2 / 10.0\n",
      "\n",
      "print ('%2d digits accuracy in storage\\n' % counter)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "16 digits accuracy in calculations\n",
        "\n",
        " 1 digits accuracy in storage\n",
        "\n"
       ]
      }
     ],
     "prompt_number": 1
    }
   ],
   "metadata": {}
  }
 ]
}