English Amiga Board BLITZ BASIC 2 "floor,ceiling and modulo% equivalent"
 Register Amiga FAQ Rules & Help Members List  /  Moderators List Today's Posts Mark Forums Read

 07 June 2014, 18:09 #1 Raislin77it Zone Friend   Join Date: Jan 2005 Location: italy Age: 40 Posts: 219 BLITZ BASIC 2 "floor,ceiling and modulo% equivalent" hi, there are this operators in blitz basic 2 ? floor ? ceiling ? modulo "%" ? i cannot find in the manual unfortunately
 08 June 2014, 00:49 #2 leathered Registered User   Join Date: Oct 2011 Location: UK Age: 41 Posts: 304 I don't think you'll find anything specifically to that effect but the manual is here: http://coagulus.newport.net/t/b.pdf If you're looking to do something 'Doomy' you might have some luck with a C2P library, Mildred is one of them. I've never used it, so can't say what it's like but there were some good examples made with one of the C2P libraries on the Blitz BUM's.
 08 June 2014, 08:39 #3 Ze Emulatron Registered User   Join Date: Nov 2010 Location: Otorohanga, New Zealand Posts: 174 From Blitz Basic 2 - Reference Guide-ENG.pdf available on http://amiga-manuals.xiik.net/amiga.php in eBooks category Blitz_Basic_2___ebook_ENG.rar -> 37328 KB For floor Function: Int Syntax: Int (Expression) Modes: Amiga/Blitz Description: This returns the Integer part (before the decimal point) of Expression. Example: Code: `Print Int(23.456) ; Will simply print 23` Mod Code: `Print 10 MOD 3 ; Will print 1` For Ceiling you could do Code: `PRINT (INT(23.456))+1` If you really want to use ceiling and floor you could do Code: ```function ceiling{n} function return (INT(n))+1 end function``` Code: ```function floor{n} function return INT(n) end function``` Last edited by Ze Emulatron; 08 June 2014 at 08:45.
08 June 2014, 11:30   #4
Raislin77it
Zone Friend

Join Date: Jan 2005
Location: italy
Age: 40
Posts: 219
Quote:
 Originally Posted by Ze Emulatron From Blitz Basic 2 - Reference Guide-ENG.pdf available on http://amiga-manuals.xiik.net/amiga.php in eBooks category Blitz_Basic_2___ebook_ENG.rar -> 37328 KB For floor Function: Int Syntax: Int (Expression) Modes: Amiga/Blitz Description: This returns the Integer part (before the decimal point) of Expression. Example: Code: `Print Int(23.456) ; Will simply print 23` Mod Code: `Print 10 MOD 3 ; Will print 1` For Ceiling you could do Code: `PRINT (INT(23.456))+1` If you really want to use ceiling and floor you could do Code: ```function ceiling{n} function return (INT(n))+1 end function``` Code: ```function floor{n} function return INT(n) end function```
thanks a lot, Ze Emulatron i have skipped the INT and MOD commands
(and thanks leathered for the sprite trick in the other thread )

08 June 2014, 12:26   #5
thomas
Registered User

Join Date: Jan 2002
Location: Germany
Posts: 5,543
Quote:
 Originally Posted by Ze Emulatron If you really want to use ceiling and floor you could do Code: ```function ceiling{n} function return (INT(n))+1 end function``` Code: ```function floor{n} function return INT(n) end function```
It's a bit more complicated than that.

These should do:

Code:
```function ceiling{n}
i = abs(int(n))
f = abs(n) - i

if f = 0 then
return n
endif

if n < 0 then
return -i
else
return i + 1
endif
end function```

Code:
```function floor{n}
i = abs(int(n))
f = abs(n) - i

if f = 0 then
return n
endif

if n < 0 then
return -i - 1
else
return i
endif
end function```
(Note that I never used (Blitz) Basic. I just adopted your syntax. So the actual syntax might need to be different.)

 08 June 2014, 14:23 #6 thomas Registered User   Join Date: Jan 2002 Location: Germany Posts: 5,543 Your ceiling example doesn't work for whole numbers, either.
08 June 2014, 19:43   #7
Ze Emulatron
Registered User

Join Date: Nov 2010
Location: Otorohanga, New Zealand
Posts: 174
Quote:
 Originally Posted by thomas It's a bit more complicated than that. These should do: Code: ```function ceiling{n} i = abs(int(n)) f = abs(n) - i if f = 0 then return n endif if n < 0 then return -i else return i + 1 endif end function``` Code: ```function floor{n} i = abs(int(n)) f = abs(n) - i if f = 0 then return n endif if n < 0 then return -i - 1 else return i endif end function``` (Note that I never used (Blitz) Basic. I just adopted your syntax. So the actual syntax might need to be different.)
Those seem to work fine when adapted to Blitz, I didn't get around to testing whole numbers or negative numbers when I wrote mine, I couldn't remember what way floor and ceil worked with negatives off the top of my head and I didn't have an environment to test them in.

Quote:
 Originally Posted by thomas Your ceiling example doesn't work for whole numbers, either.
I adapted my code to fix those issues, I think I copied the new code correctly. Sorry about the caps, I write reserved keywords in BASIC languages in caps since using amiga basic.

Code:
```FUNCTION ceiling{n}
IF SGN(n) = 1 AND FRAC(n) <> 0
FUNCTION RETURN (INT(n))+1
END IF
FUNCTION RETURN (INT(n))
END FUNCTION```
Code:
```FUNCTION floor{n}
IF SGN(n) = -1 AND FRAC(n) <> 0
FUNCTION RETURN (INT(n))-1
END IF
FUNCTION RETURN (INT(n))
END FUNCTION```

Last edited by Ze Emulatron; 08 June 2014 at 20:00.

 24 March 2015, 16:42 #8 idrougge Registered User   Join Date: Sep 2007 Location: Stockholm Posts: 3,058 I think the ceiling function is accomplished using QWrap().
26 March 2015, 22:34   #9
Cylon
Registered User

Join Date: Oct 2014
Location: Europe
Posts: 466
Quote:
 Originally Posted by idrougge I think the ceiling function is accomplished using QWrap().
No, QWrap(in,min,max) does:

IF in => max THEN in=min

As in :

Code:
```While NOT(JoyB(0))
a=QWrap (a+1,1,20)
Print a," "
VWait 25
Wend

End```
Will output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 1 2 3 4 5 ...

Furthermore, the difference in-max is added to min, if in exceeds max:

Code:
```NPrint QWrap(35,1,20)
MouseWait```
> 16

Last edited by Cylon; 28 March 2015 at 02:21. Reason: good.

 15 July 2015, 18:57 #10 Daedalus Registered User   Join Date: Jun 2009 Location: Dublin, then Glasgow Posts: 2,287 Again, just adding to this slightly old thread with another option: Use QLimit() instead of QWrap() - you give that min and max values and it gives the min value if the input is lower than the min, and the max value if the input is higher than the max. Bear in mind it only works on quick type variables so feeding it longs might give you strange results. Also, for the modulo function there is Frac() which returns the fractional part of a number. QFrac() can be used if the input is a quick type, and will execute quicker. A full version of the original Blitz Basic 2.1 manual is available here: http://www.amiblitz.de/content/blitz...mers/0001.html
 19 July 2015, 06:24 #11 Cylon Registered User   Join Date: Oct 2014 Location: Europe Posts: 466 Thanks, but the whole QWrap()/QLimit() stuff is useless if you want to use faster calculations. You have to write your own WWrap()/LWrap()/LLimit() funcs and so on. Quick types suck for advanced coding. They are nice for beginners but slow down the real sh*t.

 Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 Similar Threads Thread Thread Starter Forum Replies Last Post vroom6sri support.Games 5 11 February 2014 10:38 Gaula92 Coders. System 5 22 September 2013 22:53 rockape News 4 30 January 2013 01:06 cfTrio support.WinUAE 8 18 December 2012 17:31 emuola New to Emulation or Amiga scene 7 12 August 2009 08:09

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home News Main     Amiga scene     Retrogaming General Discussion     Nostalgia & memories Support     New to Emulation or Amiga scene         Member Introductions     support.WinUAE     support.WinFellow     support.OtherUAE     support.FS-UAE     support.Hardware         Hardware mods         Hardware pics     support.Games     support.Demos     support.Apps     support.Amiga Forever     support.Amix     support.Other Requests     request.UAE Wishlist     request.Old Rare Games     request.Demos     request.Apps     request.Modules     request.Music     request.Other     Looking for a game name ?     Games images which need to be WHDified abime.net - Hall Of Light     HOL news     HOL suggestions and feedback     HOL data problems     HOL contributions abime.net - Amiga Magazine Rack     AMR news     AMR suggestions and feedback     AMR data problems     AMR contributions abime.net - Home Projects     project.Amiga Lore     project.EAB     project.IRC     project.Mods Jukebox     project.Wiki abime.net - Hosted Projects     project.aGTW     project.APoV     project.ClassicWB     project.Jambo!     project.Green Amiga Alien GUIDES     project.Maptapper     project.Sprites     project.WinUAE - Kaillera Other Projects     project.Amiga Demo DVD     project.Amiga Game Factory     project.CARE     project.EAB File Server     project.CD32 Conversion     project.Game Cover Art         GCA.Feedback and Suggestions         GCA.Work in Progress         GCA.Cover Requests         GCA.Usefull Programs         GCA.Helpdesk     project.KGLoad     project.MAGE     project.Missing Full Shareware Games     project.SPS (was CAPS)     project.TOSEC (amiga only)     project.WHDLoad         project.Killergorilla's WHD packs Misc     Amiga websites reviews     MarketPlace         Swapshop     EAB's competition Coders     Coders. General         Coders. Releases         Coders. Tutorials     Coders. Asm / Hardware     Coders. System         Coders. Scripting         Coders. Nextgen     Coders. Language         Coders. C/C++         Coders. AMOS         Coders. Blitz Basic Off Topic     OT - General     OT - Technical     OT - Entertainment     OT - Sports     OT - Gaming

All times are GMT +2. The time now is 18:50.

 -- EAB3 skin ---- EAB2 skin ---- Mobile skin Archive - Top