File tree 2 files changed +13
-3
lines changed
2 files changed +13
-3
lines changed Original file line number Diff line number Diff line change 31
31
32
32
// these are used in TIME * MONEY action
33
33
deci deci_multiply (const deci a , const deci b );
34
+ deci deci_divide (const deci a , const deci b );
34
35
deci decimal_to_deci (REBDEC a );
35
36
36
37
/***********************************************************************
@@ -377,6 +378,7 @@ deci decimal_to_deci(REBDEC a);
377
378
REBVAL * val ;
378
379
REBVAL * arg = NULL ;
379
380
REBI64 num ;
381
+ deci hours ; // used with money type math
380
382
381
383
val = D_ARG (1 );
382
384
@@ -488,9 +490,17 @@ deci decimal_to_deci(REBDEC a);
488
490
secs = (REBI64 )(secs * VAL_DECIMAL (arg ));
489
491
goto setTime ;
490
492
}
491
- else if (type == REB_MONEY && action == A_MULTIPLY ) { // handle TIME * MONEY case
493
+ else if (type == REB_MONEY && ( action == A_MULTIPLY || action == A_DIVIDE )) {
492
494
// https://github.com/Oldes/Rebol-issues/issues/2497
493
- VAL_DECI (D_RET ) = deci_multiply (decimal_to_deci (secs * NANO / 3600.0 ), VAL_DECI (arg ));
495
+ hours = decimal_to_deci (secs * NANO / 3600.0 );
496
+ if (action == A_MULTIPLY ) {
497
+ // handle TIME * MONEY case
498
+ VAL_DECI (D_RET ) = deci_multiply (hours , VAL_DECI (arg ));
499
+ }
500
+ else {
501
+ // handle TIME / MONEY case (an horly money rate)
502
+ VAL_DECI (D_RET ) = deci_divide (VAL_DECI (arg ), hours );
503
+ }
494
504
SET_TYPE (D_RET , REB_MONEY );
495
505
return R_RET ;
496
506
}
Original file line number Diff line number Diff line change @@ -127,7 +127,7 @@ Rebol [
127
127
--test-- "time! money! math"
128
128
;@@ https://github.com/Oldes/Rebol-issues/issues/2497
129
129
--assert $7.5 = (1:30:0 * $5)
130
- --assert error? try [1:30 :0 / $5]
130
+ --assert $25 = (4:0 :0 / $100) ; an hourly rate
131
131
--assert error? try [1:30:0 + $5]
132
132
--assert error? try [1:30:0 - $5]
133
133
You can’t perform that action at this time.
0 commit comments