1 / 58

Computation for Physics 計算物理概論

Computation for Physics 計算物理概論. 數位資料表示法. Numeral systems 計數系統. Bit=Binary digit. Bit=0,1 b, bit Byte=Eight bits B K=Kilo=1000=10 3 or 1024=2 10 M=Mega=10 6 or 1024=2 20 G=Giga=10 9 or 1024=2 30 T= Tera =10 12 or 1024=2 4 0 K B=kilobyte, MB=kilobyte, GB=gigabyte. Integer.

gilles
Download Presentation

Computation for Physics 計算物理概論

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Computation for Physics計算物理概論 數位資料表示法

  2. Numeral systems計數系統

  3. Bit=Binary digit • Bit=0,1 • b, bit • Byte=Eight bits • B • K=Kilo=1000=103 or 1024=210 • M=Mega=106or 1024=220 • G=Giga=109or 1024=230 • T=Tera=1012or 1024=240 • KB=kilobyte, MB=kilobyte, GB=gigabyte

  4. Integer

  5. Unsigned integer • Map N-bits to 0,1,…,2N-1=2N possible numbers • Unsigned byte=8 bits • 0,…,255 • Unsigned short integer=16 bits • 0,…,65535 • Unsigned integer=32 bits • 0,…,4,294,967,295 • Unsigned long integer=64 bits • 0,…, 18,446,744,073,709,551,615

  6. Most and leastsignificant bit a 8-bits number Most significant bit=msb Least significant bit=lsb

  7. Signed integer How to represent negative numbers in N-bits without “-” ? • Sign-and-magnitude method • Use msbas “sign”, N-1 bits as “magnitude” • Two representations for zero • One’s complement • Use “bit complement” as the arithmetic negative • Two representations for zero • Two’s complement • Use “two’s complement of the absolute value” • One representation for zero

  8. Sign-and-magnitude sign magnitude = = = =

  9. Sign-and-magnitude • Addition of x and y • If x and y have the same sign  sgn(x)(x+y) • If x and y have different sign • If |x|>|y|  sgn(x)*(x-y) • If |y|>|x|  sgn(y)*(y-x) • Subtraction x and y=Addition of x and (-y) • If overflow return error message

  10. One’s complement = = = =

  11. One’s complement

  12. One’s complementAddition

  13. One’s complementend-around carry

  14. One’s complementnegative zero

  15. TWO’s complement = = = = =

  16. two’s complement

  17. Two’s ComplementAddition

  18. Two’s ComplementAddition ignore

  19. Two’s ComplementAddition

  20. Two’s ComplementAddition ignore

  21. Two’s ComplementAddition Positive+Positive=Negative! overflow  error message

  22. Most and leastsignificant bit a 8-bits number Most significant bit=msb Least significant bit=lsb

  23. Logic gates

  24. Logic gates邏輯閘

  25. And Gate

  26. OR Gate

  27. NOT Gate

  28. NAND Gate

  29. NOR Gate

  30. XOR Gate

  31. XNOR Gate

  32. Adder Full Adder Half Adder

  33. Real number

  34. Radix point小數點 • Base 10 notation  decimal point • Base 2 notation  binary point Radix point

  35. Scientific notation科學記號

  36. Floating pointrepresentation浮點數表示法 exponent significand (mantissa)

  37. IEEE 754 • IEEE • Institute of Electrical and Electronics Engineers • IEEE 754 • IEEE Standard for Floating-Point Arithmetic • Arithmetic formats: sets of binary and decimal floating-point data, which consist of finite numbers (including signed zeros and subnormal numbers), infinities, and special "not a number" values (NaNs) • Interchange formats: encodings (bit strings) that may be used to exchange floating-point data in an efficient and compact form • Rounding rules: properties to be satisfied when rounding numbers during arithmetic and conversions • Operations: arithmetic and other operations on arithmetic formats • Exception handling: indications of exceptional conditions (such as division by zero, overflow, etc.)

  38. IEEE 754 binary16Half precision • Sign bit: 1 bit • Exponent width: 5 bits • Significand precision: 11 (10 explicitly stored) • Exponent encoding • Offset=15, Emin=-14,Emax=15 • Minimum positive value=2^-14 • Maximum positive value=(2-2^-10)2^15=65504 • Minimum subnormal value=2^-24≈5.96×10^-5

  39. IEEE 754 binary32 single precision • Sign bit: 1 bit • Exponent width: 8 bits • Significand precision: 24 (23 explicitly stored) • Exponent encoding • Offset=127, Emin=-126,Emax=127 • Minimum positive value≈2.2 ×10^-308 • Maximum positive value≈1.8 ×10^308 • Minimum subnormal value≈4.9 ×10^-324

  40. IEEE 754 binary64Double precision • Sign bit: 1 bit • Exponent width: 11 bits • Significand precision: 53 (52 explicitly stored) • Exponent encoding • Offset=1023, Emin=-1022,Emax=1023 • Minimum positive value=2^-126≈1.18 ×10^-38 • Maximum positive value=(2-2^-23)2^127≈3.4 ×10^38 • Minimum subnormal value=2^-149≈1.4 ×10^-45

  41. Representation error

  42. Rounding Errors • In base-10 system • ½=0.5 • 1/3=0.333333333333333333333333333333333333333 • In base-2 system • Terminating iff denominators are powers of 2 (1/2, 3/16)

  43. IEEE Rounding Modes • Truncation: • Keep the desired number of digits unchanged, removing all less-significant digits; also called rounding toward zero. • 0.142857 ≈ 0.142 (All digits less significant than the third removed). • Round to Nearest: (Default) • Round to the nearest valid representation. Break ties by rounding to an even digit • +23.524, +24.524; -23.5-24, -24.5 -24 (symmetry between +/- numbers) • Round to Nearest: • Round to the nearest valid representation. Break ties by rounding away from zero. • +23.524,+24,525; -23.5-24, -24.5 -25 (symmetry between +/- numbers) • Round to −∞: • Round to a value less than or equal to the original number. If the original number is positive, this is equivalent to truncation. • Round to +∞: • Round to a value greater than or equal to the original number. If the original number is negative, this is equivalent to truncation.

  44. IEEE 754Special values • Positive infinity • Negative infinity • (positive zero=ordinary zero) • Negative zero: -0 • NaNs: “Not a number” values • Subnormal numbers

  45. Signed zero • Sign=0+ or 1- • Exponent=0 • Significand(Mantissa)=0 • Arithmetic • , , • , • , • NaN, NaN

  46. Signed infinity • Sign=0+ or 1- • Exponent=maximum value • 111112 • FFH • 7FF16 • Significand(Mantissa)=0

  47. NaNs • Sign  quiet, signaling • Exponent=maximum value • 111112 • FFH • 7FF16 • Significand(Mantissa)≠0 • Creation • NaN, NaN,NaN • NaN, =NaN • =1 or NaN • Square root or logarithm of negative number • Inverse sine or cosine of a number with absolute value greater than 1

  48. Subnormal numbers • Sign=0+ or 1- • Exponent=0 • 000002 • 00H • 00016 • Significand(Mantissa)≠0

  49. Floating pointaddition • x=123456.7 = 1.234567 × 10^5 • y=101.7654 = 1.017654 × 10^2 = 0.001017654 × 10^5 • x+y=(1.234567+0.001017654) × 10^5 • x+y=1.235584654 × 10^5 • x+y≈1.235585 × 10^5 • Round-off error!

  50. Floating point addition of a small number • x=1.234567× 10^5 • y=9.876543× 10^-3=0.00000009876543 × 10^5 • x+y=(1.234567+0.00000009876543) × 10^5 • x+y=1.23456709876543 × 10^5 • x+y≈1.234567 × 10^5=x • Round-off error!

More Related