Login
Username:

Password:

Remember me



Lost Password?

Register now!
Main Menu
Who is Online
19 user(s) are online (15 user(s) are browsing Forum)

Members: 0
Guests: 19

more...


Browsing this Thread:   1 Anonymous Users






Re: MOD function result must be INT!
#3
Just can't stay away
Just can't stay away


See User information
The last code is tested and work nice in my program. Thanks! I'm old school developer - my program must be optimized so I will be casting as many times as need. Even if I'm impressed portablE speed - portablE can draw 32000 random color filled random sized rectangles in 2 second on my sam460ex - much more than I need to my developed board game.

Posted on: 2011/3/18 11:07
 Top  Twitter  Facebook  Google Plus  Linkedin  Del.icio.us  Digg  Reddit  Mr. Wong 


Re: MOD function result must be INT!
#2
Home away from home
Home away from home


See User information
@mrdarek
On modern processors INT is usually no faster than the default type (VALUE, which is usually the same size as LONG). The main reason for using INT is to save memory!

However, it would still be useful to show how to do this, since you may run into other situations where you will want to do this for a good reason. If you were ONLY using Mod()'s first return value, then it would be easy:

Quote:
DEF z1:INT
z1 := Mod(width, height) !!INT


This is called "casting". And this would also work:
Quote:
DEF z1:INT, z2
z1, z2 := Mod(width, height) !!INT


However, since you are using two return values (both of which need casting to INT), you will have to work-around this using an extra variable:
Quote:
DEF z1:INT, z2:INT, z2temp
z1, z2temp := Mod(width, height) !!INT
z2 := z2temp !!INT


In general I find very little use for BYTE, INT & LONG, particularly for local variables (DEF), simply because they cause the need for a lot of casting, without much benefit. Therefore I feel it is best to avoid using them, except inside OBJECTs & CLASSes.

On the other hand, I often use BOOL & CHAR, because they help catch errors.

Posted on: 2011/3/14 20:11
ChrisH
--
Author of the PortablE programming language.
 Top  Twitter  Facebook  Google Plus  Linkedin  Del.icio.us  Digg  Reddit  Mr. Wong 


MOD function result must be INT!
#1
Just can't stay away
Just can't stay away


See User information
My Code:
DEF z1:INT
DEF z2:INT
z1,z2:=MOD(width,height)
----------
and got compilation error:
Hint: assigned variable has type INT, procedure's return value has type VALUE.
Speed is important in my program so I must have INT but how?


Posted on: 2011/3/13 16:24
 Top  Twitter  Facebook  Google Plus  Linkedin  Del.icio.us  Digg  Reddit  Mr. Wong 







You can view topic.
You cannot start a new topic.
You cannot reply to posts.
You cannot edit your posts.
You cannot delete your posts.
You cannot add new polls.
You cannot vote in polls.
You cannot attach files to posts.
You cannot post without approval.
You cannot use topic type.
You cannot use HTML syntax.
You cannot use signature.
You cannot create PDF files.
You cannot get print page.

[Advanced Search]


Search
Top Posters
1 paolone
paolone
4462
2 nikolaos
nikolaos
4206
3 magorium
magorium
4095
4 phoenixkonsole
phoenixkonsole
3942
5 deadwood
deadwood
2917
6 ncafferkey
ncafferkey
2810
7 mazze
mazze
2222
8 Kalamatee
Kalamatee
2212
9 clusteruk
clusteruk
2114
Powered by XOOPS © 2001-2025 The XOOPS Project