forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

'DIG' equivalent in LUAplayer?

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Lua Player Development
View previous topic :: View next topic  
Author Message
Art



Joined: 09 Nov 2005
Posts: 647

PostPosted: Sun Nov 27, 2005 7:41 am    Post subject: 'DIG' equivalent in LUAplayer? Reply with quote

Forgive me if this is obvious, I checked out the tutorial on the LUA
maths library because that's where I expected to find it...

One of my basic compilers provide a maths operation for selecting any
digit of a variable, say digit 2 of 255, and setting another variable to that value.

The syntax would be:
variable1 = variable2 DIG 2

Is there any feature like that in LUAplayer that doesn't use exsessive time?
Cheers, Art.
Back to top
View user's profile Send private message
KawaGeo



Joined: 27 Aug 2005
Posts: 191
Location: Calif Mountains

PostPosted: Sun Nov 27, 2005 12:03 pm    Post subject: Reply with quote

In order to understand what you meant:

Say, variable1 = 123. What is the result of variable2?
_________________
Geo Massar
Retired Engineer
Back to top
View user's profile Send private message Send e-mail
Art



Joined: 09 Nov 2005
Posts: 647

PostPosted: Sun Nov 27, 2005 12:24 pm    Post subject: Reply with quote

That depends on whether you start counting digits from zero or from 1.
But if you started from zero, and started counting from the least signifigant
digit, then digit 2 would be 1, so:

variable1 = 123
variable2 = 0
variable2 = variable1 DIG 2

The result stored in variable2 would now be 1.
Back to top
View user's profile Send private message
Art



Joined: 09 Nov 2005
Posts: 647

PostPosted: Sun Nov 27, 2005 2:50 pm    Post subject: Reply with quote

I can decompile the output of the compiler in question,
that will show me how it is done in RISC assembler
using small operations. That might put me in better stead
to convert it to LUA, or express it better in English :)
Art.
Back to top
View user's profile Send private message
Shine



Joined: 03 Dec 2004
Posts: 728
Location: Germany

PostPosted: Sun Nov 27, 2005 6:13 pm    Post subject: Re: 'DIG' equivalent in LUAplayer? Reply with quote

Art wrote:
Forgive me if this is obvious, I checked out the tutorial on the LUA
maths library because that's where I expected to find it...


Math is a good start, but there are many ways to implement it, e.g.:

Code:

function dig(number, digit)
   local digitValue = math.pow(10, digit)
   return math.floor(math.mod(number, digitValue) / (digitValue / 10))
end

function dig(number, digit)
   local numberString = tostring(number)
   local index = string.len(numberString) - digit + 1
   return tonumber(string.sub(numberString, index, index))
end

assert(dig(7654, 1) == 4)
assert(dig(7654, 2) == 5)
assert(dig(7654, 3) == 6)
assert(dig(7654, 4) == 7)
Back to top
View user's profile Send private message
Art



Joined: 09 Nov 2005
Posts: 647

PostPosted: Mon Nov 28, 2005 9:48 am    Post subject: Reply with quote

That's great thanx :)
I'll take the top one because it looks the most like on paper..and it looks shorter too.

102/10 = 10.2 <-- DIG 0 = 2
10/10 = 1.0 <-- DIG 1 = 0
1/10 = 0.1 <-- DIG 2 = 1

I have figured out the syntax to reverse:
var1 = dig(var4, 3)
var2 = dig(var4, 2)
var3 = dig(var4, 1)

Cheers, Art.
Back to top
View user's profile Send private message
Zenurb



Joined: 30 Sep 2005
Posts: 106
Location: United Kingdom

PostPosted: Mon Nov 28, 2005 2:07 pm    Post subject: Reply with quote

I think i see a use for this in displaying numbers from a picture font without converting the number to a string. Right?
_________________
Proud Dvorak User
US 1.5 PSP (Original)
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Art



Joined: 09 Nov 2005
Posts: 647

PostPosted: Mon Nov 28, 2005 3:03 pm    Post subject: Reply with quote

Yes, and it might also come in handy to edit individual digits in an existing number
the way you would need to with a PSP keypad.
Art.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Lua Player Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group