flang the compiler proves your program cannot hang 0.9.0 GitHub Try in the browserTry it Русский

Numbers

Numbers: sign, absolute value, integer division, GCD and LCM, power, factorial, digits.

Import:

  использует «Numbers»

Example

File example.flang:

модуль «Пример»
  использует «Numbers»

тотальная функция «Вызов из примера»
  возвращает число
  пример «Два в пятой»
    ожидается 32
  «Степень» от 2 и 5
$ flang test example.flang
example.flang: примеров 35, прошло 35, не прошло 0

The command runs the tests of the module and the test in the file: 35 in total. The value on the ожидается line comes from the test of «Степень» in the module source.

Functions

Functions to call: 15; internal: 1, listed at the end of the page.

Every postcondition has a status: proved — holds for any arguments; checked on tests only — no violation on the values from the tests, other arguments are checked at run time; not proved — there is no proof, the condition is checked at run time.

Used most often in the examples and in other modules: «Целая часть», «Целочисленное деление», «Степень», «Абсолютное значение», «Чётное», «Факториал».

«Абсолютное значение»

принимает число: число
возвращает число

Test from the module: given число = -5 returns 5.

«Целочисленное деление»

принимает делимое: число, делитель: число
возвращает число

Test from the module: given делимое = 8, делитель = 4 returns 2.

«Целая часть»

принимает значение: число
возвращает число

Test from the module: given значение = 5.5 returns 5.

«Чётное»

принимает число: число
возвращает признак

Test from the module: given число = 4 returns да.

«Степень»

принимает основание: число, показатель: неотрицательное
возвращает число

Test from the module: given основание = 2, показатель = 5 returns 32.

«Факториал»

принимает число: неотрицательное
возвращает число

Test from the module: given число = 5 returns 120.

Other functions

No other library module and no example in the repository calls these functions. The functions above are called.

«Знак»

принимает число: число
возвращает число

Test from the module: given число = 7 returns 1.

«Минимум двух»

принимает первое: число, второе: число
возвращает число

Test from the module: given первое = 2, второе = 5 returns 2.

«Максимум двух»

принимает первое: число, второе: число
возвращает число

Test from the module: given первое = 7, второе = 5 returns 7.

«Ограничить»

принимает число: число, снизу: число, сверху: число
возвращает число

Test from the module: given число = 0, снизу = 1, сверху = 9 returns 1.

«Делится на»

принимает число: число, делитель: число
возвращает признак

Test from the module: given число = 9, делитель = 3 returns да.

«НОД»

принимает первое: число, второе: число
возвращает число

Test from the module: given первое = 12, второе = 18 returns 6.

Termination is not proved: the function is declared without the word тотальная.

«НОК»

принимает первое: число, второе: число
возвращает число

Test from the module: given первое = 4, второе = 6 returns 12.

Termination is not proved: the function is declared without the word тотальная.

«Цифры»

принимает число: число
возвращает список числа

Test from the module: given число = 507 returns [5, 0, 7].

Termination is not proved: the function is declared without the word тотальная.

«Сумма цифр»

принимает число: число
возвращает число

Test from the module: given число = 507 returns 12.

Termination is not proved: the function is declared without the word тотальная.

Internal functions and types

Library modules declare no экспортирует list, so any function can be called. Internal here means by naming convention: a function «Шаг …» is a fold step, a type «Ход …» is a fold state, and so are functions that take or return such a type.

Show the list
«Шаг суммы цифр»: (акк: число, цифра: число) → число

Source: flang/stdlib/numbers.flang. All modules: Standard library.