Prolog "moddiv"
Admin User, erstellt 07. Apr. 2025
/**
* Warranty & Liability
* To the extent permitted by applicable law and unless explicitly
* otherwise agreed upon, XLOG Technologies AG makes no warranties
* regarding the provided information. XLOG Technologies AG assumes
* no liability that any problems might be solved with the information
* provided by XLOG Technologies AG.
*
* Rights & License
* All industrial property rights regarding the information - copyright
* and patent rights in particular - are the sole property of XLOG
* Technologies AG. If the company was not the originator of some
* excerpts, XLOG Technologies AG has at least obtained the right to
* reproduce, change and translate the information.
*
* Reproduction is restricted to the whole unaltered document. Reproduction
* of the information is only allowed for non-commercial uses. Selling,
* giving away or letting of the execution of the library is prohibited.
* The library can be distributed as part of your applications and libraries
* for execution provided this comment remains unchanged.
*
* Restrictions
* Only to be distributed with programs that add significant and primary
* functionality to the library. Not to be distributed with additional
* software intended to replace any components of the library.
*
* Trademarks
* Jekejeke is a registered trademark of XLOG Technologies AG.
*/
/**
* Source of test cases are the following standards:
* - Prolog General Core ISO/IEC 13211-1
* - Draft Technical Corrigendum 1, WG17, Ulrich Neumerkel
* <a href="https://www.complang.tuwien.ac.at/ulrich/iso-prolog/dtc1">www.complang.tuwien.ac.at/ulrich/iso-prolog/dtc1</a>
*/
runner_file(arithmetic, moddiv, 'ISO 9.1.7 integer').
/****************************************************************/
/* Rounding Operations */
/****************************************************************/
/* truncate(X) */
runner_pred(truncate, -2, arithmetic, moddiv, 'ISO 9.1.7.1').
runner_case(truncate, -2, arithmetic, moddiv, 'ISO 9.1.7.1, ISO 8') :-
0 is truncate(-0.5).
runner_case(truncate, -2, arithmetic, moddiv, 'ISO 9.1.7.1, XLOG 1') :-
7 is truncate(7.6).
runner_case(truncate, -2, arithmetic, moddiv, 'ISO 9.1.7.1, ISO 9') :-
catch(_ is truncate(foobar), error(E, _), true),
E == type_error(evaluable, foobar/0).
runner_case(truncate, -2, arithmetic, moddiv, 'ISO 9.1.7.1, XLOG 2') :-
-2251799813685248 is truncate(- 2^51-1/2).
runner_case(truncate, -2, arithmetic, moddiv, 'ISO 9.1.7.1, XLOG 3') :-
3 is truncate(3).
/* floor(X) */
runner_pred(floor, -2, arithmetic, moddiv, 'ISO 9.1.7.2').
runner_case(floor, -2, arithmetic, moddiv, 'ISO 9.1.7.2, ISO 1') :-
7 is floor(7.4).
runner_case(floor, -2, arithmetic, moddiv, 'ISO 9.1.7.2, ISO 2') :-
-1 is floor(-0.4).
runner_case(floor, -2, arithmetic, moddiv, 'ISO 9.1.7.2, XLOG 1') :-
2251799813685248 is floor(2^51+1/2).
runner_case(floor, -2, arithmetic, moddiv, 'ISO 9.1.7.2, XLOG 2') :-
-3 is floor(-3).
/* ceiling(X) */
runner_pred(ceiling, -2, arithmetic, moddiv, 'ISO 9.1.7.3').
runner_case(ceiling, -2, arithmetic, moddiv, 'ISO 9.1.7.3, ISO 7') :-
0 is ceiling(-0.5).
runner_case(ceiling, -2, arithmetic, moddiv, 'ISO 9.1.7.3, XLOG 1') :-
8 is ceiling(7.6).
runner_case(ceiling, -2, arithmetic, moddiv, 'ISO 9.1.7.3, XLOG 2') :-
2251799813685249 is ceiling(2^51+1/2).
runner_case(ceiling, -2, arithmetic, moddiv, 'ISO 9.1.7.3, XLOG 3') :-
3 is ceiling(3).
/* round(X) */
runner_pred(round, -2, arithmetic, moddiv, 'ISO 9.1.7.4').
runner_case(round, -2, arithmetic, moddiv, 'ISO 9.1.7.4, ISO 3') :-
8 is round(7.5).
runner_case(round, -2, arithmetic, moddiv, 'ISO 9.1.7.4, ISO 4') :-
8 is round(7.6).
runner_case(round, -2, arithmetic, moddiv, 'ISO 9.1.7.4, ISO 5') :-
-1 is round(-0.6).
runner_case(round, -2, arithmetic, moddiv, 'ISO 9.1.7.4, ISO 6') :-
catch(_ is round(_), error(E, _), true),
E == instantiation_error.
runner_case(round, -2, arithmetic, moddiv, 'ISO 9.1.7.4, XLOG 1') :-
-2251799813685248 is round(- 2^51-1/2).
runner_case(round, -2, arithmetic, moddiv, 'ISO 9.1.7.4, XLOG 2') :-
-3 is round(-3).
/* X // Y */
runner_pred(//, -3, arithmetic, moddiv, 'ISO 9.1.7.5, Corrigendum 1').
runner_case(//, -3, arithmetic, moddiv, 'ISO 9.1.7.5, ISO 21') :-
0 is 7 // 35.
runner_case(//, -3, arithmetic, moddiv, 'ISO 9.1.7.5, ISO 23') :-
10 is 140 // (3+11).
runner_case(//, -3, arithmetic, moddiv, 'ISO 9.1.7.5, XLOG 1') :-
-2 is -5 // 2.
runner_case(//, -3, arithmetic, moddiv, 'ISO 9.1.7.5, XLOG 2') :-
10 is -15211807202738 // -1394415660251.
runner_case(//, -3, arithmetic, moddiv, 'ISO 9.1.7.5, XLOG 3') :-
catch(_ is 7 // 0, error(E, _), true),
E == evaluation_error(zero_divisor).
runner_case(//, -3, arithmetic, moddiv, 'ISO 9.1.7.5, XLOG 4') :-
catch(_ is 7.5 // 3, error(E, _), true),
E = type_error(integer, 7.5).
/* X rem Y */
runner_pred(rem, -3, arithmetic, moddiv, 'ISO 9.1.7.6').
runner_case(rem, -3, arithmetic, moddiv, 'ISO 9.1.7.6, XLOG 1') :-
1 is 7 rem 3.
runner_case(rem, -3, arithmetic, moddiv, 'ISO 9.1.7.6, XLOG 2') :-
0 is 0 rem (3+11).
runner_case(rem, -3, arithmetic, moddiv, 'ISO 9.1.7.6, XLOG 3') :-
1 is 7 rem (-2).
runner_case(rem, -3, arithmetic, moddiv, 'ISO 9.1.7.6, XLOG 4') :-
-1 is -5 rem 2.
runner_case(rem, -3, arithmetic, moddiv, 'ISO 9.1.7.6, XLOG 5') :-
-1267650600228 is -15211807202738 rem -1394415660251.
runner_case(rem, -3, arithmetic, moddiv, 'ISO 9.1.7.6, XLOG 6') :-
catch(_ is 77 rem _, error(E, _), true),
E == instantiation_error.
runner_case(rem, -3, arithmetic, moddiv, 'ISO 9.1.7.6, XLOG 7') :-
catch(_ is 7 rem 0, error(E, _), true),
E == evaluation_error(zero_divisor).
runner_case(rem, -3, arithmetic, moddiv, 'ISO 9.1.7.6, XLOG 8') :-
catch(_ is 7 rem 3.5, error(E, _), true),
E == type_error(integer, 3.5).
/* X div Y, */
runner_pred(div, -3, arithmetic, moddiv, 'Corr.2 9.1.3').
runner_case(div, -3, arithmetic, moddiv, 'Corr.2 9.1.3, XLOG 1') :-
0 is 7 div 35.
runner_case(div, -3, arithmetic, moddiv, 'Corr.2 9.1.3, XLOG 2') :-
10 is 140 div (3+11).
runner_case(div, -3, arithmetic, moddiv, 'Corr.2 9.1.3, XLOG 3') :-
-3 is -5 div 2.
runner_case(div, -3, arithmetic, moddiv, 'Corr.2 9.1.3, XLOG 4') :-
10 is -15211807202738 div -1394415660251.
runner_case(div, -3, arithmetic, moddiv, 'Corr.2 9.1.3, XLOG 5') :-
catch(_ is foobar div 77, error(E, _), true),
E == type_error(evaluable, foobar/0).
runner_case(div, -3, arithmetic, moddiv, 'Corr.2 9.1.3, XLOG 6') :-
catch(_ is -7.5 div 3, error(E, _), true),
E == type_error(integer, -7.5).
/* X mod Y */
runner_pred(mod, -3, arithmetic, moddiv, 'ISO 9.1.7.7').
runner_case(mod, -3, arithmetic, moddiv, 'ISO 9.1.7.7, ISO 30') :-
1 is 7 mod 3.
runner_case(mod, -3, arithmetic, moddiv, 'ISO 9.1.7.7, ISO 31') :-
0 is 0 mod (3+11).
runner_case(mod, -3, arithmetic, moddiv, 'ISO 9.1.7.7, ISO 32') :-
-1 is 7 mod (-2).
runner_case(mod, -3, arithmetic, moddiv, 'ISO 9.1.7.7, XLOG 1') :-
-1267650600228 is -15211807202738 mod -1394415660251.
runner_case(mod, -3, arithmetic, moddiv, 'ISO 9.1.7.7, ISO 33') :-
catch(_ is 77 mod _, error(E, _), true),
E == instantiation_error.
runner_case(mod, -3, arithmetic, moddiv, 'ISO 9.1.7.7, ISO 34') :-
catch(_ is foobar mod 77, error(E, _), true),
E == type_error(evaluable, foobar/0).
runner_case(mod, -3, arithmetic, moddiv, 'ISO 9.1.7.7, ISO 36') :-
catch(_ is 7 mod 0, error(E, _), true),
E == evaluation_error(zero_divisor).
runner_case(mod, -3, arithmetic, moddiv, 'ISO 9.1.7.7, XLOG 2') :-
catch(_ is -7 mod 3.5, error(E, _), true),
E == type_error(integer, 3.5).