DEVELOPMENT EDITION · 769442725406
Library Reference
On this page

Verada.Vibe.Floats

Python's float operations that Ada has no operator for, for Vibe.

Read the family guide for representation, selection and resource rules. The complete declaration page retains exact signatures/contracts; the source specification is the implementation baseline.

Availability and ownership

Modulo, Floor_Divide, Round, Round_Digits and Power are Python's %, //, round and ** of floats, as CPython computes them; the run time does the arithmetic, and the contracts state what a client proof may use. The compiler uses this unit when it translates Vibe; programs do not need to import it.

Import and instantiate

with Verada.Vibe.Floats;
import Verada.Vibe.Floats;

A Vibe module uses these through Python's operators; see library use across syntaxes.

Contract and lifecycle reading

A Pre condition is the caller's obligation; a Post is what a normal return guarantees. What a postcondition does not state, a client cannot assume.

API 001

Modulo (declaration) — Python's x % y of floats: the remainder with y's sign, from the exact remainder, as CPython computes it.

Declared interface:

function Modulo (X, Y : Long_Float) return Long_Float
  with Import, Convention => Ada, External_Name => "verada_rt_float_mod",
       Global => null,
       Pre => Y /= 0.0,
       Post => abs Modulo'Result < abs Y
               and then (if Modulo'Result /= 0.0 then (Modulo'Result < 0.0) = (Y < 0.0));

API 002

Floor_Divide (declaration) — Python's x // y of floats: the floor of the quotient, as CPython computes it.

Declared interface:

function Floor_Divide (X, Y : Long_Float) return Long_Float
  with Import, Convention => Ada, External_Name => "verada_rt_float_floor_div",
       Global => null,
       Pre => Y /= 0.0 and then abs (X / Y) <= Long_Float'Last,
       Post => Floor_Divide'Result = Long_Float'Floor (Floor_Divide'Result);

API 003

Round (declaration) — Python's round(x): the nearest int, a half to the even one.

Declared interface:

function Round (X : Long_Float) return Integer
  with Import, Convention => Ada, External_Name => "verada_rt_float_round",
       Global => null,
       Pre => X >= -9.2233720368547748E18 and then X <= 9.2233720368547748E18,
       Post => abs (Long_Float (Round'Result) - X) <= 0.5;

API 004

Round_Digits (declaration) — Python's round(x, n): x rounded at n digits after the point (before it for a negative n), from its exact value.

Declared interface:

function Round_Digits (X : Long_Float; Count : Integer) return Long_Float
  with Import, Convention => Ada, External_Name => "verada_rt_float_round_digits",
       Global => null,
       Post => (if Count >= 0 and then X >= 0.0 then Round_Digits'Result >= 0.0)
               and then (if Count >= 0 and then X <= 0.0 then Round_Digits'Result <= 0.0);

API 005

Power (declaration) — Python's x ** y of floats: a real power; a negative base takes a whole exponent.

Declared interface:

function Power (X, Y : Long_Float) return Long_Float
  with Import, Convention => Ada, External_Name => "verada_rt_float_power",
       Global => null,
       Pre => X > 0.0 or else (X = 0.0 and then Y > 0.0) or else (X < 0.0 and then Y = Long_Float'Floor (Y)),
       Post => (if X > 0.0 then Power'Result >= 0.0);