Skip to content

Commit 57be8a4

Browse files
committed
added best practices
1 parent efb2c4d commit 57be8a4

File tree

8 files changed

+129
-36
lines changed

8 files changed

+129
-36
lines changed

bibliography/bibliography.bib

Lines changed: 90 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ @string { a_back_ralph_johan
2929
@string { a_bai_junjie = "Junjie Bai" }
3030
@string { a_barham_paul = "Paul Barham" }
3131
@string { a_barret_daniel_j = "Daniel J. Barrett" }
32+
@string { a_baumgartner_gary = "Gary Baumgartner" }
3233
@string { a_beazley_david_m = "David M.\ Beazley" }
3334
@string { a_beigel_richard = "Richard Beigel" }
3435
@string { a_ben_david_shai = "Shai Ben{-}David" }
@@ -56,6 +57,7 @@ @string { a_chilamkurthy_sasank
5657
@string { a_chintala_soumith = "Soumith Chintala" }
5758
@string { a_cimran_robert = "Robert Cimrman" }
5859
@string { a_clinton_david = "David Clinton" }
60+
@string { a_coghlan_alyssa = "Alyssa Coghlan" }
5961
@string { a_cornapeau_david = "David Cournapeau" }
6062
@string { a_d_alche_buc_florence = "Florence d'Alch{\'e}{-}Buc" }
6163
@string { a_da_veiga_leprevost_felipe = "Felipe {da Veiga Leprevost}" }
@@ -73,6 +75,7 @@ @string { a_fang_lu
7375
@string { a_feng_yu = "Yu Feng" }
7476
@string { a_fernandez_del_rio_jaime = "Jaime {Fern{\'a}ndez del R{\'i}o}" }
7577
@string { a_filaseta_michael = "Michael Filaseta" }
78+
@string { a_flannery_brian_p = "Brian P.\ Flannery" }
7679
@string { a_flight_robert_m = "Robert M.\ Flight" }
7780
@string { a_fox_emily_b = "Emily B.\ Fox" }
7881
@string { a_fufezan_christian = "Christian Fufezan" }
@@ -86,13 +89,15 @@ @string { a_gommers_ralf
8689
@string { a_gramfort_alexandre = "Alexandre Gramfort" }
8790
@string { a_grendell_lina = "Linda Grandell" }
8891
@string { a_grisel_olivier = "Olivier Grisel" }
92+
@string { a_goodger_david = "David Goodger" }
8993
@string { a_gross_sam = "Sam Gross" }
9094
@string { a_grus_joel = "Joel Grus" }
9195
@string { a_grys_slawomir = "S{\l}awomir Gry{\'s}" }
9296
@string { a_haberland_matt = "Matt Haberland" }
9397
@string { a_haldane_allan = "Allan Haldane" }
9498
@string { a_harris_charles_r = "Charles R.\ Harris" }
9599
@string { a_hausenblas_michael = "Michael Hausenblas" }
100+
@string { a_heap_danny = "Danny Heap" }
96101
@string { a_henriksen_ian = "Ian Henriksen" }
97102
@string { a_hollasch_steve = "Steve Hollasch" }
98103
@string { a_hoyer_stephan = "Stephan Hoyer" }
@@ -109,6 +114,7 @@ @string { a_kern_robert
109114
@string { a_killeen_trevor = "Trevor Killeen" }
110115
@string { a_klopf_andreas = "Andreas K{\"o}pf" }
111116
@string { a_konovalov_alexander = "Alexander Konovalov" }
117+
@string { a_krueger_richard = "Richard Krueger" }
112118
@string { a_kudlur_manjunath = "Manjunath Kudlur" }
113119
@string { a_landau_charles = "Charles Landau" }
114120
@string { a_larochelle_hugo = "Hugo Larochelle" }
@@ -155,6 +161,7 @@ @string { a_peterson_pearu
155161
@string { a_picus_matti = "Matti Picus" }
156162
@string { a_polat_ilhan = "Ilhan Polat" }
157163
@string { a_pollard_tom_j = "Tom J.\ Pollard" }
164+
@string { a_press_william_h = "William H.\ Press" }
158165
@string { a_prettenhofer_peter = "Peter Prettenhofer" }
159166
@string { a_quinter_ea = "E.\ A.\ Quintero" }
160167
@string { a_raison_martin = "Martin Raison" }
@@ -178,6 +185,7 @@ @string { a_steiner_benoit
178185
@string { a_taylor_julian = "Julian Taylor" }
179186
@string { a_tejani_alykhan = "Alykhan Tejani" }
180187
@string { a_ternent_tobias = "Tobias Ternent" }
188+
@string { a_teukolsky_saul_a = "Saul A.\ Teukolsky" }
181189
@string { a_thirion_bertrand = "Bertrand Thirion" }
182190
@string { a_tolhurst_denise = "Denise Tolhurst" }
183191
@string { a_torregrossa_dario = "Dario Torregrossa" }
@@ -194,12 +202,14 @@ @string { a_van_rossum_guido
194202
@string { a_van_rysdam = "Peter {van Rysdam}" }
195203
@string { a_varoquaux_gael = "Ga{\"e}l Varoquaux" }
196204
@string { a_vasudevan_vijay = "Vijay Vasudevan" }
205+
@string { a_vetterling_william_t = "William T.\ Vetterling" }
197206
@string { a_virtanen_pauli = "Pauli Virtanen" }
198207
@string { a_vizcaino_juan_antonio = "Juan Antonio Vizca{\'i}no" }
199208
@string { a_wallach_hanna_m = "Hanna M.\ Wallach" }
200209
@string { a_wang_rui = "Rui Wang" }
201210
@string { a_warden_pete = "Pete Warden" }
202-
@string { a_warren_weckesser = "Warren Weckesser" }
211+
@string { a_warsaw_barry = "Barry Warsaw" }
212+
@string { a_weckesser_warren = "Warren Weckesser" }
203213
@string { a_weise_thomas = "Thomas Weise" }
204214
@string { a_weiss_ron = "Ron Weiss" }
205215
@string { a_wicke_martin = "Martin Wicke" }
@@ -218,6 +228,7 @@ @string { a_zinoviev_dimitry
218228
%% locations
219229
@string { l_australia_hobart = "{{Hobart}, {TAS}, {Australia}}" }
220230
@string { l_canada_oakville = "{{Oakville}, {ON}, {Canada}}" }
231+
@string { l_canada_toronto = "{{Toronto}, {ON}, {Canada}}" }
221232
@string { l_canada_vancouver = "{{Vancouver}, {BC}, {Canada}}" }
222233
@string { l_china_beijing = "{{China}, {Beijing}}" }
223234
@string { l_portugal_lisbon = "{{Lisbon}, {Portugal}}" }
@@ -283,6 +294,7 @@ @string { p_springer_new_york
283294
@string { p_taylor_and_francis = "{Taylor and Francis Ltd.}" }
284295
@string { p_unicode_consortium = "{The Unicode Consortium}" }
285296
@string { p_university_of_south_carolina = "{University of South Carolina}" }
297+
@string { p_university_of_toronto_cs = "{{Department of Computer Science}, {University of Toronto}}" }
286298
@string { p_university_of_washington = "{University of Washington}" }
287299
@string { p_usas = "{United States of America Standards Institute~{(USAS)}}" }
288300
@string { p_usenix = "{{USENIX} Association}" }
@@ -320,6 +332,7 @@ @string { pa_springer_nature_limited
320332
@string { pa_springer_new_york = l_usa_new_york }
321333
@string { pa_unicode_consortium = l_usa_south_san_francisco }
322334
@string { pa_university_of_south_carolina = l_usa_columbia }
335+
@string { pa_university_of_toronto_cs = l_canada_toronto }
323336
@string { pa_university_of_washington = l_usa_seattle }
324337
@string { pa_usas = l_usa_new_york }
325338
@string { pa_usenix = l_usa_berkeley }
@@ -436,6 +449,12 @@ @xdata{rep_ieee_standard
436449
type = {{IEEE}~Std},
437450
}
438451

452+
@xdata{rep_pep,
453+
type = {Python Enhancement Proposal~{(PEP)}},
454+
institution = p_python_software_foundation,
455+
address = pa_python_software_foundation
456+
}
457+
439458
@xdata{rep_nsotprocg,
440459
type = {National Standard of the People's Republic of China~{(GB)}},
441460
address = l_china_beijing
@@ -571,6 +590,24 @@ @book{B2023W1IO
571590
execute = {\sloppy}
572591
}
573592

593+
@book{BHK2006CNFCMEARFCS,
594+
author = a_baumgartner_gary # and # a_heap_danny # and # a_krueger_richard,
595+
title = {Course Notes for {CSC165H}: Mathematical Expression and Reasoning for Computer Science},
596+
date = {2006-23},
597+
publisher = p_university_of_toronto_cs,
598+
address = pa_university_of_toronto_cs,
599+
url = {https://www.cs.toronto.edu/~krueger/csc165h/f06},
600+
urldate = {2024-07-27}
601+
}
602+
603+
@inbook{BHK2006NS,
604+
title = {Numerical Systems},
605+
chapter = {7},
606+
crossref = {BHK2006CNFCMEARFCS},
607+
url = {https://www.cs.toronto.edu/~krueger/csc165h/f06/lectures/ch7.pdf},
608+
urldate = {2024-07-27}
609+
}
610+
574611
@article{CBST2024LOHPPTDDSAMLA,
575612
author = a_castro_oscar # and # a_bruneau_pierrix # and # a_sottet_jean_sebastien # and # a_torregrossa_dario,
576613
title = {Landscape of High-Performance \python\ to Develop Data Science and Machine Learning Applications},
@@ -722,7 +759,7 @@ @book{H2023ABGTP3P
722759
}
723760

724761
@article{HMvdWGVCWTBSKPHvKBHFdRWPGMSRWAGO2020APWN,
725-
author = a_harris_charles_r # and # a_millman_jarrod_k # and # a_van_der_walt_stefan # and # a_gommers_ralf # and # a_virtanen_pauli # and # a_cornapeau_david # and # a_wieser_eric # and # a_taylor_julian # and # a_berg_sebastian # and # a_smith_nathaniel_j # and # a_kern_robert # and # a_picus_matti # and # a_hoyer_stephan # and # a_van_kerkwijk_marten_h # and # a_brett_matthew # and # a_haldane_allan # and # a_fernandez_del_rio_jaime # and # a_wiebe_mark # and # a_peterson_pearu # and # a_gerard_marchant_pierre # and # a_sheppart_kevin # and # a_reddy_tyler # and # a_warren_weckesser # and # a_abbasi_hameer # and # a_gohlke_christoph # and # a_oliphant_travis_e,
762+
author = a_harris_charles_r # and # a_millman_jarrod_k # and # a_van_der_walt_stefan # and # a_gommers_ralf # and # a_virtanen_pauli # and # a_cornapeau_david # and # a_wieser_eric # and # a_taylor_julian # and # a_berg_sebastian # and # a_smith_nathaniel_j # and # a_kern_robert # and # a_picus_matti # and # a_hoyer_stephan # and # a_van_kerkwijk_marten_h # and # a_brett_matthew # and # a_haldane_allan # and # a_fernandez_del_rio_jaime # and # a_wiebe_mark # and # a_peterson_pearu # and # a_gerard_marchant_pierre # and # a_sheppart_kevin # and # a_reddy_tyler # and # a_weckesser_warren # and # a_abbasi_hameer # and # a_gohlke_christoph # and # a_oliphant_travis_e,
726763
title = {Array programming with \numpy},
727764
xdata = {j_n},
728765
volume = {585},
@@ -847,6 +884,36 @@ @book{P2021HOMLPAVWP
847884
isbn = {9781484274101}
848885
}
849886

887+
@techreport{PEP8,
888+
title = {Style Guide for Python Code},
889+
author = a_van_rossum_guido # and # a_warsaw_barry # and # a_coghlan_alyssa,
890+
xdata = {rep_pep},
891+
number = {8},
892+
date = {2001-07-05},
893+
url = {https://peps.python.org/pep-0008},
894+
urldate = {2024-07-27}
895+
}
896+
897+
@techreport{PEP257,
898+
title = {Docstring Conventions},
899+
author = a_goodger_david # and # a_van_rossum_guido,
900+
number = {257},
901+
xdata = {rep_pep},
902+
date = {2001-05-29},
903+
url = {https://peps.python.org/pep-0257},
904+
urldate = {2024-07-27},
905+
}
906+
907+
@techreport{PEP498,
908+
author = a_smith_eric_v,
909+
title = {Literal String Interpolation},
910+
xdata = {rep_pep},
911+
number = {498},
912+
date = {2016-11-06/2023-09-09},
913+
url = {https://peps.python.org/pep-0498},
914+
urldate = {2024-07-25},
915+
}
916+
850917
@inproceedings{PGMLBCKLGADKYDRTCSFBC2019PAISHPDLL,
851918
author = a_paszke_adam # and # a_gross_sam # and # a_massa_francisco # and # a_lerer_adam # and # a_bradbury_james # and # a_chanan_gregory # and # a_killeen_trevor # and # a_lin_zeming # and # a_gimelshein_natalia # and # a_antiga_luca # and # a_desmaison_alban # and # a_klopf_andreas # and # a_yang_edward_z # and # a_devito_zachary # and # a_raison_martin # and # a_tejani_alykhan # and # a_chilamkurthy_sasank # and # a_steiner_benoit # and # a_fang_lu # and # a_bai_junjie # and # a_chintala_soumith,
852919
title = {\pytorch: An Imperative Style, High-Performance Deep Learning Library},
@@ -940,6 +1007,26 @@ @inbook{PSF2024TSTS
9401007
urldate = {2024-07-25},
9411008
}
9421009

1010+
@inbook{PTVF2007EAAS,
1011+
title = {1.1~Error, Accuracy, and Stability},
1012+
chapter = {1~Preliminaries},
1013+
pages = {8--12},
1014+
crossref = {PTVF2007NRTAOSC}
1015+
}
1016+
1017+
@book{PTVF2007NRTAOSC,
1018+
author = a_press_william_h # and # a_teukolsky_saul_a # and # a_vetterling_william_t # and # a_flannery_brian_p,
1019+
title = {Numerical Recipes: The Art of Scientific Computing},
1020+
edition = {3},
1021+
date = {2007/2011},
1022+
note = {Version~3.04},
1023+
publisher = p_cambridge_uni_press_ass,
1024+
address = pa_cambridge_uni_press_ass,
1025+
isbn = {978-0-521-88068-8},
1026+
url = {https://numerical.recipes/book.html},
1027+
urldate = {2024-07-27},
1028+
}
1029+
9431030
@article{PVGMTGBPWDVPCBPD2011SMLIP,
9441031
author = a_pedregosa_fabian # and # a_varoquaux_gael # and # a_gramfort_alexandre # and # a_michel_vincent # and # a_thirion_bertrand # and # a_grisel_olivier # and # a_blondel_mathieu # and # a_prettenhofer_peter # and # a_weiss_ron # and # a_dubourg_vincent # and # a_vanderplas_jake # and # a_passos_alexandre # and # a_cornapeau_david # and # a_brucher_matthieu # and # a_perrot_matthieu # and # a_duchesnay_edouard,
9451032
title = {\scikitlearn: Machine Learning in \python},
@@ -981,16 +1068,6 @@ @article{S1988WPCHD
9811068
pages = {117},
9821069
}
9831070

984-
@book{S2016P4LSI,
985-
author = a_smith_eric_v,
986-
title = {PEP~498 -- Literal String Interpolation},
987-
publisher = p_python_software_foundation,
988-
address = pa_python_software_foundation,
989-
date = {2016-11-06/2023-09-09},
990-
url = {https://peps.python.org/pep-0498},
991-
urldate = {2024-07-25},
992-
}
993-
9941071
@book{S2023LG,
9951072
author = a_skoulikari_anna,
9961073
title = {Learning \git},
@@ -1071,7 +1148,7 @@ @techreport{USAS1967USCFII
10711148
}
10721149

10731150
@article{VGOHRCBPWBvdWBWMMNJKLCPFMVLPCHQHARPvMS2020SFAFSCIP,
1074-
author = a_virtanen_pauli # and # a_gommers_ralf # and # a_oliphant_travis_e # and # a_haberland_matt # and # a_reddy_tyler # and # a_cornapeau_david # and # a_burovski_evgeni # and # a_peterson_pearu # and # a_warren_weckesser # and # a_bright_jonathan # and # a_van_der_walt_stefan # and # a_brett_matthew # and # a_wilson_joshua # and # a_millman_jarrod_k # and # a_mayorov_nikolay # and # a_nelson_andrew_r_j # and # a_jones_eric # and # a_kern_robert # and # a_larson_eric # and # a_carey_cj # and # a_polat_ilhan # and # a_feng_yu # and # a_moore_eric_w # and # a_vanderplas_jake # and # a_laxalde_denis # and # a_perktold_josef # and # a_cimran_robert # and # a_henriksen_ian # and # a_quinter_ea # and # a_harris_charles_r # and # a_archibald_anne_m # and # a_ribeiro_antonio_h # and # a_pedregosa_fabian # and # a_van_mulbregt_paul # and # a_scipy_1,
1151+
author = a_virtanen_pauli # and # a_gommers_ralf # and # a_oliphant_travis_e # and # a_haberland_matt # and # a_reddy_tyler # and # a_cornapeau_david # and # a_burovski_evgeni # and # a_peterson_pearu # and # a_weckesser_warren # and # a_bright_jonathan # and # a_van_der_walt_stefan # and # a_brett_matthew # and # a_wilson_joshua # and # a_millman_jarrod_k # and # a_mayorov_nikolay # and # a_nelson_andrew_r_j # and # a_jones_eric # and # a_kern_robert # and # a_larson_eric # and # a_carey_cj # and # a_polat_ilhan # and # a_feng_yu # and # a_moore_eric_w # and # a_vanderplas_jake # and # a_laxalde_denis # and # a_perktold_josef # and # a_cimran_robert # and # a_henriksen_ian # and # a_quinter_ea # and # a_harris_charles_r # and # a_archibald_anne_m # and # a_ribeiro_antonio_h # and # a_pedregosa_fabian # and # a_van_mulbregt_paul # and # a_scipy_1,
10751152
title = {\scipy~1.0:~Fundamental Algorithms for Scientific Computing in \python},
10761153
xdata = {j_nm},
10771154
date = {2020-03-02},

styles/colors.sty

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@
5151
%%
5252
\colorlet{definition-frame}{hfuu-red!70}%
5353
\colorlet{definition-background}{hfuu-orange!20}%
54-
\colorlet{ruleofthumb-frame}{OliveGreen!50}%
55-
\colorlet{ruleofthumb-background}{Aquamarine!20}%
54+
\colorlet{bestpractice-frame}{OliveGreen!50}%
55+
\colorlet{bestpractice-background}{Aquamarine!20}%
5656
%
5757
%%
5858
%% Table Coloring

styles/definitions.sty

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,32 @@ rightmargin=5pt,%
1515
font={}%
1616
]{definition}{\definitionautorefname}[chapter]%
1717
%
18-
\newcommand{\@ruleOfThumbautorefname}{Rule of Thumb}%
18+
\newcommand{\@bestPracticeautorefname}{Best Practice}%
1919
%
2020
\newmdtheoremenv[%
2121
linewidth=2pt,%
22-
linecolor=ruleofthumb-frame,%
22+
linecolor=bestpractice-frame,%
2323
roundcorner=4pt,%
24-
backgroundcolor=ruleofthumb-background,%
24+
backgroundcolor=bestpractice-background,%
2525
leftmargin=5pt,%
2626
rightmargin=5pt,%
2727
font={}%
28-
]{@ruleOfThumb}{\@ruleOfThumbautorefname}%
29-
%%
30-
\xdef\@rulesOfThumb{}%
28+
]{@bestPractice}{\@bestPracticeautorefname}%
29+
%
30+
\xdef\@bestPractices{}%
3131
%
32-
\gdef\ruleOfThumb#1#2{%
33-
\begin{@ruleOfThumb}\label{rule:#1}#2\end{@ruleOfThumb}%
32+
\gdef\bestPractice#1#2{%
33+
\begin{@bestPractice}\label{bp:#1}#2\end{@bestPractice}%
3434
%
35-
\ifx\@rulesOfThumbs\empty\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi%
36-
{\gdef\@rulesOfThumb{\noindent\autoref{rule:#1}:~#2}}%
37-
{\g@addto@macro\@rulesOfThumb{\medskip\par\noindent\autoref{rule:#1}: #2}}%
35+
\ifx\@bestPractices\empty\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi%
36+
{\gdef\@bestPractices{\noindent\cref{bp:#1}:~#2}}%
37+
{\g@addto@macro\@bestPractices{\medskip\par\noindent\cref{bp:#1}: #2}}%
3838
}%
3939
%
40-
\gdef\printRulesOfThumb{%
41-
\chapter*{Rules of Thumb}%
42-
\pdfbookmark{Rules of Thumb}{Rules of Thumb}%
43-
\@rulesOfThumb%
40+
\gdef\printBestPractices{%
41+
\chapter*{Best Practices}%
42+
\pdfbookmark{Best Practices}{Best Practices}%
43+
\@bestPractices%
4444
}%
4545
%
4646
\protected\gdef\noviceHint#1{%

styles/styles.sty

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,6 @@
3333
\RequirePackage[sort&compress,capitalise,nameinlink,noabbrev]{cleveref}%
3434
\creflabelformat{equation}{#2\textup{#1}#3}%%
3535
\crefrangelabelformat{equation}{#3\textup{#1}#4 to~#5\textup{#2}#6}%
36-
\crefname{@ruleOfThumb}{Rule of Thumb}{Rules of Thumb}%
36+
\crefname{@bestPractice}{\@bestPracticeautorefname}{\@bestPracticeautorefname}%
37+
\Crefname{@bestPractice}{\@bestPracticeautorefname}{\@bestPracticeautorefname}%
3738
%

text/back/backmatter.tex

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
\setulmarginsandblock{2.5cm}{2.5cm}{*}%0
99
\checkandfixthelayout%
1010
%
11-
%\printRulesOfThumb%
12-
%\printsymbols%
11+
\printBestPractices%
1312
\printacronyms%
1413
\printglossaries%
1514
%

text/main/basics/simpleDataTypesAndOperations/float/float.tex

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
In other words, regardless whether your \pythonilIdx{float} stores a very large or a very small number, you can have at most 15~digits of precision.
6767
For example, adding~1 to~$10^{16}$ would still yield~$10^{16}$, because only 15~digits are \inQuotes{stored} and the~1 will just \inQuotes{fall off.}
6868
You cannot represent numbers arbitrarily precisely.%
69+
%
6970
\endhsection%
7071
%
7172
\hsection{Floating Point Arithmetic}%
@@ -138,6 +139,17 @@
138139
Calculating \pythonil{asin(sin(0.925))}\pythonIdx{asin}\pythonIdx{sin} indeed yields~\pythonil{0.9250000000000002}.
139140
Due to the periodicity of the trigonometric functions, $\arccos{\cos{-0.3}}$ is~$0.3$ and \pythonil{acos(cos(-0.3))}\pythonIdx{acos}\pythonIdx{cos} results in~\pythonil{0.30000000000000016}.
140141
For $\arctan{\tan{1}}$ we even get the exact result \pythonil{1.0} by computing \pythonil{atan(tan(1))}\pythonIdx{atan}\pythonIdx{tan}.%
142+
%
143+
\bestPractice{floatImprecise}{%
144+
Always assume that any \pythonilIdx{float} value is imprecise. %
145+
Never expect it to be exact~\cite{PTVF2007EAAS,BHK2006NS}.%
146+
}%
147+
%
148+
Due to the limited precision, it could be that you add two numbers $c=a+b$ but then find that $c-a\neq b$, because some digit was lost. %
149+
This is obvious when adding a very small number to a very large number.
150+
We only have about 15~digits, so doing something like~$10^{20} + 1$ will usually work out to just be~$10^{20}$ in floating point arithmetics~\cite{PTVF2007EAAS}.
151+
But digits could also be lost when adding numbers of roughly the same scale, because their sum could just be larger so that the 15-digit-window shifts such that the least-significant digit falls off~\cite{BHK2006NS}{\dots}%
152+
%
141153
\endhsection%
142154
%
143155
\hsection{Back to Integers: Rounding}%

text/main/basics/simpleDataTypesAndOperations/int/int.tex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@
5656
Computing \pythonil{32 / 4} thus yields~\pythonil{8.0}, \pythonil{33 / 4} gives us \pythonil{8.25}, \pythonil{34 / 4} yields~\pythonil{8.5}, \pythonil{35 / 4} results in \pythonil{8.75}, and, finally, \pythonil{36 / 4} returns~\pythonil{9.0}.
5757
Notice that the result of this division operator is always a floating point number, even if the number itself is an integer.
5858

59+
\bestPractice{intDivision}{Always be careful with which division operator you use for \pythonilIdx{int}s. If you need an integer result, make sure to use \pythonilIdx{//}. Remember that \pythonilIdx{/} always returns a \pythonilIdx{float} (and see \cref{bp:floatImprecise}), even if the result is a whole number.}
60+
5961
Now above we have said that \pythonil{33 // 4} yields the integer~\pythonil{8}.
6062
The remainder of this operation can be computed using the \pgls{modulodiv} operator \expandafter\pythonilIdx{\%}, i.e., by typing \pythonil{33 \% 4}, which yields~\pythonil{1}.
6163
We also find that \expandafter\pythonil{34 \% 4} yields~\pythonil{2}, \expandafter\pythonil{35 \% 4} gives us~\pythonil{3}, and \expandafter\pythonil{36 \% 4} is~\pythonil{0}.

0 commit comments

Comments
 (0)