[m-rev.] for review: allow string.base_string_to_int to parse int.min_int literals
Ian MacLarty
maclarty at csse.unimelb.edu.au
Thu Jan 14 14:20:30 AEDT 2010
On Thu, Jan 14, 2010 at 11:10:57AM +1100, Julien Fischer wrote:
>
> On Thu, 14 Jan 2010, Ralph Becket wrote:
>
>> Ian MacLarty, Thursday, 14 January 2010:
>>> On Thu, Jan 14, 2010 at 8:33 AM, Julien Fischer
>>>> I think the intent of Ralph's question is: can you now use the literal
>>>> -9223372036854775808 on 64-bit machines?
>>>
>>> Yes, that should also now be possible, although I haven't tested that
>>> case. I'll test that before I commit, but I'm not sure if I could add
>>> that test to the test suite so that it would also work on 32 bit
>>> machines (?).
>>
>> Another case for conditional compilation :-)
>
> Hardly! Just call int.bits_per_int/0 and then adapt the test
> accordingly depending on the returned value.
>
I changed the test case to the following, which gives the same results
on 64 and 32 bit machines:
Index: tests/general/base_string_to_int_test.m
===================================================================
RCS file: /home/mercury1/repository/tests/general/base_string_to_int_test.m,v
retrieving revision 1.1
diff -u -r1.1 base_string_to_int_test.m
--- tests/general/base_string_to_int_test.m 1 Jul 2004 06:20:14 -0000 1.1
+++ tests/general/base_string_to_int_test.m 14 Jan 2010 01:19:27 -0000
@@ -21,7 +21,7 @@
:- implementation.
-:- import_module int, list, string.
+:- import_module int, list, require, string.
%-----------------------------------------------------------------------------%
@@ -35,8 +35,19 @@
test("123abc", !IO),
test("abc", !IO),
test("+abc", !IO),
- test("-abc", !IO).
-
+ test("-abc", !IO),
+ ( int.bits_per_int = 32 ->
+ MinIntStr = "-2147483648"
+ ; int.bits_per_int = 64 ->
+ MinIntStr = "-9223372036854775808"
+ ;
+ error("unknown architecture")
+ ),
+ ( string.base_string_to_int(10, MinIntStr, int.min_int) ->
+ io.write_string("min_int ok.\n", !IO)
+ ;
+ io.write_string("min_int failed.\n", !IO)
+ ).
:- pred test(string::in, io::di, io::uo) is det.
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to: mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions: mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------
More information about the reviews
mailing list