add comments to all public interfaces

This commit is contained in:
jacekpoz 2024-03-22 14:24:09 +01:00
parent dc00760c91
commit 0591d86aab
Signed by: poz
SSH key fingerprint: SHA256:JyLeVWE4bF3tDnFeUpUaJsPsNlJyBldDGV/dIKSLyN8
7 changed files with 80 additions and 0 deletions

View file

@ -3,15 +3,30 @@
#include <stdint.h> #include <stdint.h>
/*
* computes the factorial of n
* only works on natural numbers
*/
uint64_t factorial(uint64_t n); uint64_t factorial(uint64_t n);
/*
* computes the gcd of a and b
* only works on natural numbers
*/
uint64_t gcd(uint64_t a, uint64_t b); uint64_t gcd(uint64_t a, uint64_t b);
/*
* the solution of a linear diophantine equation
*/
typedef struct { typedef struct {
int64_t n; int64_t n;
int64_t m; int64_t m;
} Result; } Result;
/*
* computes the solution of a linear diophantine equation ax + by = c
* or returns NULL if it doesn't exist
*/
Result *diophantine(int64_t a, int64_t b, int64_t c); Result *diophantine(int64_t a, int64_t b, int64_t c);
#endif // _JPP_L1_Z1_MOD_H #endif // _JPP_L1_Z1_MOD_H

View file

@ -3,16 +3,23 @@ with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
package Module is package Module is
-- computes the factorial of n
-- only works on natural numbers
function gcd(a : Natural; b : Natural) return Natural; function gcd(a : Natural; b : Natural) return Natural;
-- computes the gcd of a and b
-- only works on natural numbers
function factorial(n : Natural) return Natural; function factorial(n : Natural) return Natural;
-- the solution of a linear diophantine equation
type Result is record type Result is record
resultExists : Boolean; resultExists : Boolean;
n : Integer; n : Integer;
m : Integer; m : Integer;
end record; end record;
-- computes the solution of a linear diophantine equation ax + by = c
-- if the solution doesn't exist Result::resultExists == false
function diophantine(a : Integer; b : Integer; c : Integer) return Result; function diophantine(a : Integer; b : Integer; c : Integer) return Result;
end Module; end Module;

View file

@ -1,8 +1,14 @@
pub trait Module { pub trait Module {
/// computes the factorial of n
/// only works on natural numbers
fn factorial(&self, n: u64) -> u64; fn factorial(&self, n: u64) -> u64;
/// computes the gcd of a and b
/// only works on natural numbers
fn gcd(&self, a: u64, b: u64) -> u64; fn gcd(&self, a: u64, b: u64) -> u64;
/// computes the solution of a linear diophantine equation ax + by = c
/// or returns None if it doesn't exist
fn diophantine(&self, a: i64, b: i64, c: i64) -> Option<(i64, i64)>; fn diophantine(&self, a: i64, b: i64, c: i64) -> Option<(i64, i64)>;
} }

View file

@ -3,16 +3,31 @@
#include <stdbool.h> #include <stdbool.h>
/*
* computes the gcd of a and b
* only works on natural numbers
*/
extern unsigned int gcd(unsigned int a, unsigned int b); extern unsigned int gcd(unsigned int a, unsigned int b);
/*
* computes the factorial of n
* only works on natural numbers
*/
extern unsigned int factorial(unsigned int n); extern unsigned int factorial(unsigned int n);
/*
* the solution of a linear diophantine equation
*/
typedef struct { typedef struct {
bool resultExists; bool resultExists;
int n; int n;
int m; int m;
} Result; } Result;
/*
* computes the solution of a linear diophantine equation ax + by = c
* if the solution doesn't exist Result::resultExists == false
*/
extern Result diophantine(int a, int b, int c); extern Result diophantine(int a, int b, int c);
#endif // _JPP_L1_Z4_WRAPPER_H #endif // _JPP_L1_Z4_WRAPPER_H

View file

@ -4,16 +4,31 @@
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
/*
* computes the factorial of n
* only works on natural numbers
*/
unsigned int factorial(unsigned int n); unsigned int factorial(unsigned int n);
/*
* computes the gcd of a and b
* only works on natural numbers
*/
unsigned int gcd(unsigned int a, unsigned int b); unsigned int gcd(unsigned int a, unsigned int b);
/*
* the solution of a linear diophantine equation
*/
typedef struct { typedef struct {
bool resultExists; bool resultExists;
int n; int n;
int m; int m;
} Result; } Result;
/*
* computes the solution of a linear diophantine equation ax + by = c
* if the solution doesn't exist Result::resultExists == false
*/
Result diophantine(int a, int b, int c); Result diophantine(int a, int b, int c);
#endif // _JPP_L1_Z5_MOD_H #endif // _JPP_L1_Z5_MOD_H

View file

@ -1,5 +1,6 @@
use std::{env, process::exit}; use std::{env, process::exit};
/// the solution of a linear diophantine equation
#[repr(C)] #[repr(C)]
pub struct Result { pub struct Result {
pub resultExists: libc::c_int, pub resultExists: libc::c_int,
@ -8,10 +9,16 @@ pub struct Result {
} }
extern "C" { extern "C" {
/// computes the gcd of a and b
/// only works on natural numbers
pub fn gcd(a: libc::c_uint, b: libc::c_uint) -> libc::c_uint; pub fn gcd(a: libc::c_uint, b: libc::c_uint) -> libc::c_uint;
/// computes the factorial of n
/// only works on natural numbers
pub fn factorial(n: libc::c_uint) -> libc::c_uint; pub fn factorial(n: libc::c_uint) -> libc::c_uint;
/// computes the solution of a linear diophantine equation ax + by = c
/// if the solution doesn't exist Result::resultExists == false
pub fn diophantine(a: libc::c_int, b: libc::c_int, c: libc::c_int) -> Result; pub fn diophantine(a: libc::c_int, b: libc::c_int, c: libc::c_int) -> Result;
} }

View file

@ -3,16 +3,31 @@
#include <stdbool.h> #include <stdbool.h>
/*
* computes the gcd of a and b
* only works on natural numbers
*/
extern unsigned int gcd(unsigned int a, unsigned int b); extern unsigned int gcd(unsigned int a, unsigned int b);
/*
* computes the factorial of n
* only works on natural numbers
*/
extern unsigned int factorial(unsigned int n); extern unsigned int factorial(unsigned int n);
/*
* the solution of a linear diophantine equation
*/
typedef struct { typedef struct {
bool resultExists; bool resultExists;
int n; int n;
int m; int m;
} Result; } Result;
/*
* computes the solution of a linear diophantine equation ax + by = c
* if the solution doesn't exist Result::resultExists == false
*/
extern Result diophantine(int a, int b, int c); extern Result diophantine(int a, int b, int c);
#endif // _JPP_L1_Z7_WRAPPER_H #endif // _JPP_L1_Z7_WRAPPER_H