Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0dbd1fd

Browse files
committed
correct description of integer division; describe optional read arg
1 parent 3e43d83 commit 0dbd1fd

2 files changed

Lines changed: 22 additions & 16 deletions

File tree

Doc/lib/libtypes.tex

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,9 @@ \subsection{Numeric Types}
215215
\begin{description}
216216

217217
\item[(1)]
218-
For (plain or long) integer division, the result is an integer; it
219-
always truncates towards zero.
220-
% XXXJH integer division is better defined nowadays
218+
For (plain or long) integer division, the result is an integer.
219+
The result is always rounded towards minus infinity: 1/2 is 0,
220+
(-1)/2 is -1, 1/(-2) is -1, and (-1)/(-2) is 0.
221221
\indexii{integer}{division}
222222
\indexiii{long}{integer}{division}
223223

@@ -666,17 +666,17 @@ \subsubsection{File Objects}
666666
\code{0}.
667667
\end{funcdesc}
668668

669-
\begin{funcdesc}{read}{size}
669+
\begin{funcdesc}{read}{\optional{size}}
670670
Read at most \var{size} bytes from the file (less if the read hits
671671
\EOF{} or no more data is immediately available on a pipe, tty or
672-
similar device). If the \var{size} argument is omitted, read all
673-
data until \EOF{} is reached. The bytes are returned as a string
672+
similar device). If the \var{size} argument is negative or omitted,
673+
read all data until \EOF{} is reached. The bytes are returned as a string
674674
object. An empty string is returned when \EOF{} is encountered
675675
immediately. (For certain files, like ttys, it makes sense to
676676
continue reading after an \EOF{} is hit.)
677677
\end{funcdesc}
678678

679-
\begin{funcdesc}{readline}{}
679+
\begin{funcdesc}{readline}optional{size}}
680680
Read one entire line from the file. A trailing newline character is
681681
kept in the string%
682682
\footnote{The advantage of leaving the newline on is that an empty string
@@ -686,7 +686,10 @@ \subsubsection{File Objects}
686686
you can tell whether the last line of a file ended in a newline
687687
or not (yes this happens!).}
688688
(but may be absent when a file ends with an
689-
incomplete line). An empty string is returned when \EOF{} is hit
689+
incomplete line). If thevar{size} argument is present and
690+
non-negative, it is a maximum byte count (including the trailing
691+
newline) and an incomplete line may be returned.
692+
An empty string is returned when \EOF{} is hit
690693
immediately. Note: unlike \code{stdio}'s \code{fgets()}, the returned
691694
string contains null characters (\code{'\e 0'}) if they occurred in the
692695
input.

Doc/libtypes.tex

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,9 @@ \subsection{Numeric Types}
215215
\begin{description}
216216

217217
\item[(1)]
218-
For (plain or long) integer division, the result is an integer; it
219-
always truncates towards zero.
220-
% XXXJH integer division is better defined nowadays
218+
For (plain or long) integer division, the result is an integer.
219+
The result is always rounded towards minus infinity: 1/2 is 0,
220+
(-1)/2 is -1, 1/(-2) is -1, and (-1)/(-2) is 0.
221221
\indexii{integer}{division}
222222
\indexiii{long}{integer}{division}
223223

@@ -666,17 +666,17 @@ \subsubsection{File Objects}
666666
\code{0}.
667667
\end{funcdesc}
668668

669-
\begin{funcdesc}{read}{size}
669+
\begin{funcdesc}{read}{\optional{size}}
670670
Read at most \var{size} bytes from the file (less if the read hits
671671
\EOF{} or no more data is immediately available on a pipe, tty or
672-
similar device). If the \var{size} argument is omitted, read all
673-
data until \EOF{} is reached. The bytes are returned as a string
672+
similar device). If the \var{size} argument is negative or omitted,
673+
read all data until \EOF{} is reached. The bytes are returned as a string
674674
object. An empty string is returned when \EOF{} is encountered
675675
immediately. (For certain files, like ttys, it makes sense to
676676
continue reading after an \EOF{} is hit.)
677677
\end{funcdesc}
678678

679-
\begin{funcdesc}{readline}{}
679+
\begin{funcdesc}{readline}optional{size}}
680680
Read one entire line from the file. A trailing newline character is
681681
kept in the string%
682682
\footnote{The advantage of leaving the newline on is that an empty string
@@ -686,7 +686,10 @@ \subsubsection{File Objects}
686686
you can tell whether the last line of a file ended in a newline
687687
or not (yes this happens!).}
688688
(but may be absent when a file ends with an
689-
incomplete line). An empty string is returned when \EOF{} is hit
689+
incomplete line). If thevar{size} argument is present and
690+
non-negative, it is a maximum byte count (including the trailing
691+
newline) and an incomplete line may be returned.
692+
An empty string is returned when \EOF{} is hit
690693
immediately. Note: unlike \code{stdio}'s \code{fgets()}, the returned
691694
string contains null characters (\code{'\e 0'}) if they occurred in the
692695
input.

0 commit comments

Comments
 (0)