[m-rev.] diff: add functions returning the min/max values for fixed size types
Julien Fischer
jfischer at opturion.com
Thu Aug 31 14:25:08 AEST 2017
Add functions returning the min/max value for fixed size int types.
library/int{8,16,32}.m:
Add min_int* and max_int*.
library/uint{8,16,32}.m:
Add max_uint*. Where this was already defined using foreign_procs,
use Mercury clauses instead.
Julien.
diff --git a/library/int32.m b/library/int32.m
index 3311e1581..694766f10 100644
--- a/library/int32.m
+++ b/library/int32.m
@@ -193,6 +193,10 @@
%
:- func \ (int32::in) = (int32::uo) is det.
+:- func min_int32 = int32.
+
+:- func max_int32 = int32.
+
% Convert a int32 to a pretty_printer.doc for formatting.
%
:- func int32_to_doc(int32) = pretty_printer.doc.
@@ -404,6 +408,12 @@ odd(X) :-
%---------------------------------------------------------------------------%
+min_int32 = -2_147_483_648_i32.
+
+max_int32 = 2_147_483_647_i32.
+
+%---------------------------------------------------------------------------%
+
int32_to_doc(X) = str(string.int32_to_string(X)).
%---------------------------------------------------------------------------%
diff --git a/library/uint16.m b/library/uint16.m
index 63cf097bf..4c04057b8 100644
--- a/library/uint16.m
+++ b/library/uint16.m
@@ -177,6 +177,8 @@
%
:- func \ (uint16::in) = (uint16::uo) is det.
+:- func max_uint16 = uint16.
+
% Convert a uint16 to a pretty_printer.doc for formatting.
%
:- func uint16_to_doc(uint16) = pretty_printer.doc.
@@ -326,6 +328,10 @@ odd(X) :-
%---------------------------------------------------------------------------%
+max_uint16 = 65_535_u16.
+
+%---------------------------------------------------------------------------%
+
uint16_to_doc(X) = str(string.uint16_to_string(X)).
%---------------------------------------------------------------------------%
diff --git a/library/uint32.m b/library/uint32.m
index ec6507534..e7c2d8975 100644
--- a/library/uint32.m
+++ b/library/uint32.m
@@ -353,30 +353,7 @@ odd(X) :-
%---------------------------------------------------------------------------%
-:- pragma foreign_proc("C",
- max_uint32 = (U::out),
- [will_not_call_mercury, promise_pure, thread_safe, will_not_modify_trail],
-"
- U = UINT32_MAX;
-").
-
-:- pragma foreign_proc("C#",
- max_uint32 = (U::out),
- [will_not_call_mercury, promise_pure, thread_safe],
-"
- U = uint.MaxValue;
-").
-
-:- pragma foreign_proc("Java",
- max_uint32 = (U::out),
- [will_not_call_mercury, promise_pure, thread_safe],
-"
- U = 0xffffffff;
-").
-
-:- pragma no_determinism_warning(max_uint32/0).
-max_uint32 = _ :-
- sorry($module, "uint32.max_uint32/0 NYI for Erlang").
+max_uint32 = 4_294_967_295_u32.
%---------------------------------------------------------------------------%
diff --git a/library/uint8.m b/library/uint8.m
index 7d853d542..5acdf681f 100644
--- a/library/uint8.m
+++ b/library/uint8.m
@@ -177,6 +177,8 @@
%
:- func \ (uint8::in) = (uint8::uo) is det.
+:- func max_uint8 = uint8.
+
% Convert an uint8 to a pretty_printer.doc for formatting.
%
:- func uint8_to_doc(uint8) = pretty_printer.doc.
@@ -326,6 +328,10 @@ odd(X) :-
%---------------------------------------------------------------------------%
+max_uint8 = 255_u8.
+
+%---------------------------------------------------------------------------%
+
uint8_to_doc(X) = str(string.uint8_to_string(X)).
%---------------------------------------------------------------------------%
More information about the reviews
mailing list