Оберон-клуб «ВЄДАsoft» https://zx.oberon.org/forum/ |
|
get a percentage of an integer? https://zx.oberon.org/forum/viewtopic.php?f=10&t=136 |
Страница 1 из 1 |
Автор: | slenkar [ 22 авг 2013, 21:05 ] |
Заголовок сообщения: | get a percentage of an integer? |
Hi I want to get a percentage of an integer but I cant multiply an integer by a REAL Код: "OBERON"
Код: "OBERON"
we are tring to get 45% of 6 Код: "OBERON"
percentage =45 Код: "OBERON"
incompatible assignment! |
Автор: | Zorko [ 23 авг 2013, 08:38 ] |
Заголовок сообщения: | Re: get a percentage of an integer? |
Just use: Код: "OBERON"
DIV is integer division. If you need to use "traditional" integer division (as in Pascal and C), there is option in SYSTEM_Cfg.h: Код: "C" #define SYSTEM_Cfg_DIV_as_in_C Oberon has more "right", more mathematic division designed by scientists (differences are for negative numbers), you can read the paper "Division and Modulus for Computer Scientists" to know about it more. What division will be more efficient? I think, now it is DIV_as_in_C (for the current implementation of high-level DIV based on C division). But it may be improved by implementing the "right" Oberon's DIV by a low-level routine written in assembler. |
Автор: | slenkar [ 23 авг 2013, 19:22 ] |
Заголовок сообщения: | Re: get a percentage of an integer? |
thanks I cant seem to get any sound, have you tried it? Код: "OBERON"
|
Автор: | Zorko [ 23 авг 2013, 19:43 ] | |||
Заголовок сообщения: | Re: get a percentage of an integer? | |||
This code works perfectly without any changes (I just have added (*$MAIN) ). Try to run the code as you provided. Basic.BEEP is the same that ZX Basic's BEEP, but duration is set in milliseconds. If the code not works inside your game - maybe you have used BEEP before initializing module Basic? P.S. Haven't you update Basic.h & Basic.c after I made fix for BEEP for IM2 mode? (and don't forget to rebuild Basic).
|
Автор: | slenkar [ 23 авг 2013, 21:18 ] |
Заголовок сообщения: | Re: get a percentage of an integer? |
I replaced Basic.c and .h and it works now thanks! |
Автор: | Saferoll [ 28 авг 2013, 13:58 ] |
Заголовок сообщения: | Re: get a percentage of an integer? |
Zorko писал(а): Note, DIV divides without rounding, fraction is truncated (discarded).Example: 79*10%=7.9 in REAL. It is 7 with truncating (formula above), the rounding makes 8. Thе formula with rounding (to the right) must be Код: "OBERON"
|
Автор: | Zorko [ 28 авг 2013, 18:07 ] |
Заголовок сообщения: | Re: get a percentage of an integer? |
You are absolutely right, Saferoll. I forget about it, and it's important for increase the precision more. Oberon has not a function ROUND like in Pascal/Delphi, that rounds REALs not by truncating the fraction. But Oberon just has ENTIER, and ROUND may be implemented in easy way like: Код: "OBERON"
|
Страница 1 из 1 | Часовой пояс: UTC + 2 часа |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |