Commit bfb563e120fa743dfaf31a6d476c2795a620d78e

Authored by Chunk
0 parents
Exists in master

first commit

.idea/Numerical.iml 0 → 100644
  1 +++ a/.idea/Numerical.iml
... ... @@ -0,0 +1,8 @@
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<module type="PYTHON_MODULE" version="4">
  3 + <component name="NewModuleRootManager">
  4 + <content url="file://$MODULE_DIR$" />
  5 + <orderEntry type="jdk" jdkName="Python 2.7.6 virtualenv at ~/.virtualenvs/env0" jdkType="Python SDK" />
  6 + <orderEntry type="sourceFolder" forTests="false" />
  7 + </component>
  8 +</module>
0 9 \ No newline at end of file
... ...
.idea/misc.xml 0 → 100644
  1 +++ a/.idea/misc.xml
... ... @@ -0,0 +1,14 @@
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<project version="4">
  3 + <component name="ProjectLevelVcsManager" settingsEditedManually="false">
  4 + <OptionsSetting value="true" id="Add" />
  5 + <OptionsSetting value="true" id="Remove" />
  6 + <OptionsSetting value="true" id="Checkout" />
  7 + <OptionsSetting value="true" id="Update" />
  8 + <OptionsSetting value="true" id="Status" />
  9 + <OptionsSetting value="true" id="Edit" />
  10 + <ConfirmationsSetting value="0" id="Add" />
  11 + <ConfirmationsSetting value="0" id="Remove" />
  12 + </component>
  13 + <component name="ProjectRootManager" version="2" project-jdk-name="Python 2.7.6 (/usr/bin/python2.7)" project-jdk-type="Python SDK" />
  14 +</project>
0 15 \ No newline at end of file
... ...
.idea/modules.xml 0 → 100644
  1 +++ a/.idea/modules.xml
... ... @@ -0,0 +1,8 @@
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<project version="4">
  3 + <component name="ProjectModuleManager">
  4 + <modules>
  5 + <module fileurl="file://$PROJECT_DIR$/.idea/Numerical.iml" filepath="$PROJECT_DIR$/.idea/Numerical.iml" />
  6 + </modules>
  7 + </component>
  8 +</project>
0 9 \ No newline at end of file
... ...
.idea/vcs.xml 0 → 100644
  1 +++ a/.idea/vcs.xml
... ... @@ -0,0 +1,6 @@
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<project version="4">
  3 + <component name="VcsDirectoryMappings">
  4 + <mapping directory="" vcs="" />
  5 + </component>
  6 +</project>
0 7 \ No newline at end of file
... ...
.idea/workspace.xml 0 → 100644
  1 +++ a/.idea/workspace.xml
... ... @@ -0,0 +1,43 @@
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<project version="4">
  3 + <component name="ChangeListManager">
  4 + <option name="TRACKING_ENABLED" value="true" />
  5 + <option name="SHOW_DIALOG" value="false" />
  6 + <option name="HIGHLIGHT_CONFLICTS" value="true" />
  7 + <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
  8 + <option name="LAST_RESOLUTION" value="IGNORE" />
  9 + </component>
  10 + <component name="ChangesViewManager" flattened_view="true" show_ignored="false" />
  11 + <component name="CreatePatchCommitExecutor">
  12 + <option name="PATCH_PATH" value="" />
  13 + </component>
  14 + <component name="NamedScopeManager">
  15 + <order />
  16 + </component>
  17 + <component name="ProjectLevelVcsManager" settingsEditedManually="false">
  18 + <OptionsSetting value="true" id="Add" />
  19 + <OptionsSetting value="true" id="Remove" />
  20 + <OptionsSetting value="true" id="Checkout" />
  21 + <OptionsSetting value="true" id="Update" />
  22 + <OptionsSetting value="true" id="Status" />
  23 + <OptionsSetting value="true" id="Edit" />
  24 + <ConfirmationsSetting value="0" id="Add" />
  25 + <ConfirmationsSetting value="0" id="Remove" />
  26 + </component>
  27 + <component name="ShelveChangesManager" show_recycled="false" />
  28 + <component name="TaskManager">
  29 + <task active="true" id="Default" summary="Default task">
  30 + <created>1434792298659</created>
  31 + <option name="number" value="Default" />
  32 + <updated>1434792298659</updated>
  33 + </task>
  34 + <servers />
  35 + </component>
  36 + <component name="VcsContentAnnotationSettings">
  37 + <option name="myLimit" value="2678400000" />
  38 + </component>
  39 + <component name="XDebuggerManager">
  40 + <breakpoint-manager />
  41 + <watches-manager />
  42 + </component>
  43 +</project>
0 44 \ No newline at end of file
... ...
chap1/1_3_infiniteseries.py 0 → 100644
  1 +++ a/chap1/1_3_infiniteseries.py
... ... @@ -0,0 +1,48 @@
  1 +__author__ = 'chunk'
  2 +
  3 +import struct
  4 +
  5 +
  6 +def float2bits(f, fmt='bin'):
  7 + if fmt == 'hex':
  8 + return hex(struct.unpack('!l', struct.pack('!f', f))[0])
  9 + return bin(struct.unpack('!l', struct.pack('!f', f))[0])
  10 +
  11 +
  12 +def double2bits(d, fmt='bin'):
  13 + if fmt == 'hex':
  14 + return hex(struct.unpack('!q', struct.pack('!d', d))[0])
  15 + return bin(struct.unpack('!q', struct.pack('!d', d))[0])
  16 +
  17 +
  18 +def float2bin(num):
  19 + # http://stackoverflow.com/questions/16444726/binary-representation-of-float-in-python-bits-not-hex
  20 + bits = [bin(ord(c)).replace('0b', '').rjust(8, '0') for c in struct.pack('!f', num)]
  21 + print bits
  22 + return ''.join(bits)
  23 +
  24 +
  25 +def double2bin(num):
  26 + # http://stackoverflow.com/questions/16444726/binary-representation-of-float-in-python-bits-not-hex
  27 + bits = [bin(ord(c)).replace('0b', '').rjust(8, '0') for c in struct.pack('!d', num)]
  28 + print bits
  29 + return ''.join(bits)
  30 +
  31 +
  32 +def infiniteseries():
  33 + s = 0
  34 + tmp = -1
  35 + i = 0
  36 + while float(s) != float(tmp):
  37 + i += 1
  38 + tmp = s
  39 + s += float(1.0 / i)
  40 + print tmp,s
  41 +
  42 + print i, s, tmp
  43 +
  44 +
  45 +if __name__ == '__main__':
  46 + print float2bin(1.0)
  47 + infiniteseries()
  48 + pass
... ...
chap1/__init__.py 0 → 100644
  1 +++ a/chap1/__init__.py
... ... @@ -0,0 +1 @@
  1 +__author__ = 'chunk'
... ...
main.py 0 → 100644
  1 +++ a/main.py
... ... @@ -0,0 +1 @@
  1 +__author__ = 'chunk'
... ...