Home Explore Blog CI



neovim

68th chunk of `runtime/doc/luaref.txt`
368a6f6ac482ab8d9c2ffc106c44c5f28caaf2c47766e7510000000100000fa0
 the expression `x^y` to compute this
        value.)

math.rad({x})                                                       *math.rad()*
        Returns the angle {x} (given in degrees) in radians.

math.random([{m} [, {n}]])                                       *math.random()*
        This function is an interface to the simple pseudo-random generator
        function `rand` provided by ANSI C. (No guarantees can be given for
        its statistical properties.)

        When called without arguments, returns a pseudo-random real number in
        the range `[0,1)`. When called with a number {m}, `math.random`
        returns a pseudo-random integer in the range `[1, m]`. When called
        with two numbers {m} and {n}, `math.random` returns a pseudo-random
        integer in the range `[m, n]`.

math.randomseed({x})                                         *math.randomseed()*
        Sets {x} as the "seed" for the pseudo-random generator: equal seeds
        produce equal sequences of numbers.

math.sin({x})                                                       *math.sin()*
        Returns the sine of {x} (assumed to be in radians).

math.sinh({x})                                                     *math.sinh()*
        Returns the hyperbolic sine of {x}.

math.sqrt({x})                                                     *math.sqrt()*
        Returns the square root of {x}. (You can also use the expression
        `x^0.5` to compute this value.)

math.tan({x})                                                       *math.tan()*
        Returns the tangent of {x} (assumed to be in radians).

math.tanh({x})                                                     *math.tanh()*
        Returns the hyperbolic tangent of {x}.

==============================================================================
5.6  Input and Output Facilities                                  *lua-lib-io*

The I/O library provides two different styles for file manipulation. The first
one uses implicit file descriptors; that is, there are operations to set a
default input file and a default output file, and all input/output operations
are over these default files. The second style uses explicit file
descriptors.

When using implicit file descriptors, all operations are supplied by
table `io`. When using explicit file descriptors, the operation `io.open` returns
a file descriptor and then all operations are supplied as methods of the file
descriptor.

The table `io` also provides three predefined file descriptors with their usual
meanings from C: `io.stdin`, `io.stdout`, and `io.stderr`.

Unless otherwise stated, all I/O functions return `nil` on failure (plus an
error message as a second result) and some value different from `nil` on
success.

io.close([{file}])                                                  *io.close()*
        Equivalent to `file:close`. Without a {file}, closes the default
        output file.

io.flush()                                                          *io.flush()*
        Equivalent to `file:flush` over the default output file.

io.input([{file}])                                                  *io.input()*
        When called with a file name, it opens the named file (in text mode),
        and sets its handle as the default input file. When called with a file
        handle, it simply sets this file handle as the default input file.
        When called without parameters, it returns the current default input
        file.

        In case of errors this function raises the error, instead of returning
        an error code.

io.lines([{filename}])                                              *io.lines()*
        Opens the given file name in read mode and returns an |iterator|
        function that, each time it is called, returns a new line from the
        file. Therefore, the construction

        `for line in io.lines(filename) do`  `body`  `end`

        will iterate over all lines of the file. When the iterator function

Title: Lua Math Library: Trigonometric Functions, Random Number Generation, and I/O Facilities Introduction
Summary
This section continues the description of the Lua `math` library, covering `math.sin`, `math.sinh`, `math.sqrt`, `math.tan`, and `math.tanh`. It also details how to use the random number generator (`math.random` and `math.randomseed`). Then, the text introduces Lua's I/O facilities, outlining two styles of file manipulation (implicit and explicit file descriptors) and predefined file descriptors (`io.stdin`, `io.stdout`, `io.stderr`). The section also covers `io.close`, `io.flush`, `io.input`, and `io.lines` functions.