non-integer_20modulo_20operation
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
non-integer_20modulo_20operation [2018/03/31 13:19] – external edit 127.0.0.1 | non-integer_20modulo_20operation [2024/01/05 00:21] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
=====Non-integer modulo operation===== | =====Non-integer modulo operation===== | ||
- | //by Richard Russell, November 2011//\\ \\ | + | //by Richard Russell, November 2011// |
+ | |||
+ | BBC BASIC, in common with several other languages (e.g. C), provides only an integer [[http:// | ||
+ | |||
+ | <code bb4w> | ||
PRINT 678.9 MOD 123.45 | PRINT 678.9 MOD 123.45 | ||
- | prints the value **63**.\\ \\ | + | </ |
+ | |||
+ | prints the value **63**. | ||
+ | |||
+ | However the [[http:// | ||
+ | |||
+ | <code bb4w> | ||
DEF FNfmod(x,y) = x - x DIV y * y | DEF FNfmod(x,y) = x - x DIV y * y | ||
- | Now we can perform the following operation:\\ | + | </ |
+ | |||
+ | Now we can perform the following operation: | ||
+ | |||
+ | <code bb4w> | ||
PRINT FNfmod(678.9, | PRINT FNfmod(678.9, | ||
- | and the value printed is **61.65**.\\ \\ The **FNfmod** function listed above is restricted to values in the range -2147483648 to +2147483647 because of the use of the **DIV** operator. If you need an extended range (assuming *FLOAT64 mode is in use) the following function may be used:\\ \\ | + | </ |
- | DEF FNfmod(x,y) = x - SGNx * INT ABS(x/y) * ABSy | + | |
+ | and the value printed is **61.65**. |
non-integer_20modulo_20operation.1522502369.txt.gz · Last modified: 2024/01/05 00:17 (external edit)