Author 
Message 

Bwyard
Newbie
Joined: 28 Apr 2009 Posts: 17

Posted: 16 Oct 2009 07:41:27 pm Post subject: 


can someone heilp me to figure out how to calculate the number of digits in a variable using logs or something of thta nature. I had a friend that has done it on a casio but i dont have access to that code to see how he did it. So could someone please help m efigure this out.
i need this for a program.
say the number is 1.5645 i need to determine how many digits are in that number in the program. i need to have itr out put 5. actually it would be better if we could get it to output how many characters are in a number including decimals and  signs.
Last edited by Guest on 16 Oct 2009 08:25:41 pm; edited 1 time in total 

Back to top 


GloryMXE7 Puzzleman 3000
Active Member
Joined: 02 Nov 2008 Posts: 604

Posted: 16 Oct 2009 08:12:37 pm Post subject: 


ok here
set Y_{1} as 1.5645
then use
Equ>String(Y_{1},Str1
length(Str1
it should output 6 

Back to top 


Bwyard
Newbie
Joined: 28 Apr 2009 Posts: 17

Posted: 16 Oct 2009 08:30:29 pm Post subject: 


thats not what i need. what i am doing is calculating a number then i need to determine the number of digits of that calculated number that is stored in a variable. i need to do that without any human input besides the number needed for calculation. 

Back to top 


Bwyard
Newbie
Joined: 28 Apr 2009 Posts: 17

Posted: 16 Oct 2009 08:31:38 pm Post subject: 


actually that would help only if i could store a variable into the Y_{1}. but i cant. 

Back to top 


ztrumpet
Active Member
Joined: 06 May 2009 Posts: 555

Posted: 16 Oct 2009 08:49:56 pm Post subject: 


You can store the number into Y1 (with extra characters) , but it's not pretty:
(Stores A into Str1)
{0,1→L1
{0,N→L2
LinReg(ax+B) Y1
Equ►String(Y1,Str1
sub(Str1,1,length(Str1)3→Str1
Also a great place for people to learn stuff about the commands:
http://tibasicdev.wikidot.com/home
Last edited by Guest on 05 Jul 2010 07:52:40 am; edited 1 time in total 

Back to top 


Bwyard
Newbie
Joined: 28 Apr 2009 Posts: 17

Posted: 16 Oct 2009 08:58:49 pm Post subject: 


ok that might help. but if u know how i can determine the digits without strings that would be great. I do know its possible b/c ive seen it done but i dont remember the code 

Back to top 


ztrumpet
Active Member
Joined: 06 May 2009 Posts: 555

Posted: 16 Oct 2009 09:08:05 pm Post subject: 


You can use log( but that woln't help unless it's a whole number.
1+int(log(Ans
(Returns number of digits of Ans) 

Back to top 


Bwyard
Newbie
Joined: 28 Apr 2009 Posts: 17

Posted: 16 Oct 2009 09:16:07 pm Post subject: 


yeah ztrumpet what ur saying works but only for whole numbers. meaning positive integers., which is exactly what u said. But my friend did it using logs maybe natural logs, but anyways he did it to determine if the number inputed was radian or degrees. by determining that if the digits are infinite then it is radian. and if it has a certain number than it is degrees.
Last edited by Guest on 16 Oct 2009 09:19:47 pm; edited 1 time in total 

Back to top 


Weregoose Authentic INTJ
Super Elite (Last Title)
Joined: 25 Nov 2004 Posts: 3976

Posted: 16 Oct 2009 11:50:16 pm Post subject: 


The string approach, while effective, is a bit overkill. Try this:
Ans→X
While fPart(Ans
10Ans
End
1+(Ans≠X)+(Ans<0)+int(log(abs(Ans
That is,
 Save the input.
 If there's a fractional part, start looping from here until the fractional part is gone.
 Multiply by ten (repeatedly, if need be).
 Either reset to the top of the loop or exit the loop, depending on whether there's still a fractional part.
 With the loop exited (and with the number now an integer), start with 1, add 1 for the decimal point if the number has changed (i.e., if there was a fractional part to get rid of in the first place), add another 1 for the negative sign if the number is less than 0, and then add the floor of the logarithm of the integer.
Though, that's not an especially good way to determine what mode you're in.
If it's radians, then sin([font="times new roman"]π would equal 0. If sin([font="times new roman"]π is not zero, then you're using degrees.
Does that make sense?
Last edited by Guest on 05 Jul 2010 07:53:15 am; edited 1 time in total 

Back to top 


Bwyard
Newbie
Joined: 28 Apr 2009 Posts: 17

Posted: 17 Oct 2009 03:30:35 am Post subject: 


weregoose i am completely lost. 

Back to top 


Bwyard
Newbie
Joined: 28 Apr 2009 Posts: 17

Posted: 17 Oct 2009 10:05:31 am Post subject: 


Weregoose wrote:
 Save the input.
 If there's a fractional part, start looping from here until the fractional part is gone.
 Multiply by ten (repeatedly, if need be).
 Either reset to the top of the loop or exit the loop, depending on whether there's still a fractional part.
 With the loop exited (and with the number now an integer), start with 1, add 1 for the decimal point if the number has changed (i.e., if there was a fractional part to get rid of in the first place), add another 1 for the negative sign if the number is less than 0, and then add the floor of the logarithm of the integer.
i dont understand the last step could u please show some code
 Edit 
i think i got it i had my code wrong so it wasnt working properly thanks alot
Last edited by Guest on 17 Oct 2009 10:08:17 am; edited 1 time in total 

Back to top 


ztrumpet
Active Member
Joined: 06 May 2009 Posts: 555

Posted: 17 Oct 2009 11:44:26 am Post subject: 


The code is in Weregoose's post He's just explaining how it works. 

Back to top 


Bwyard
Newbie
Joined: 28 Apr 2009 Posts: 17

Posted: 17 Oct 2009 11:53:34 am Post subject: 


ok i need some more help. so far i got it working but i also want to display the answer as a fraction no matter what.
so heres what i am doing
Code: Lbl BR
B→R
While fPart(R
10R→R
End
1+(R≠B)+(R<0)+int(log(abs(R→R
Disp ""
Output(4,4,"Fraction Form
Disp ""
Output(5,1,"(
Output(5,2,B
Output(5,2+R,"+
Output(5,3+R,i
Output(5,4+R,real(22,I)
length(real(22,I→H
Output(5,4+R+H,")
Also where it says real(22,I) i am using an hook or whatever it is called and it actually simplifies the root
so since I is 72 when i do a=3 b=6 and c=9 then that should output 6√2 but sadly it does not can someone please help.
let me clarify when not in the program it does output 6√2 but while in the program it doesnt.
Last edited by Guest on 17 Oct 2009 12:00:30 pm; edited 1 time in total 

Back to top 


ztrumpet
Active Member
Joined: 06 May 2009 Posts: 555


Back to top 


Bwyard
Newbie
Joined: 28 Apr 2009 Posts: 17

Posted: 17 Oct 2009 04:32:07 pm Post subject: 


Thanks alot ztrumpet. this really helps.
Last edited by Guest on 17 Oct 2009 04:51:34 pm; edited 1 time in total 

Back to top 


ztrumpet
Active Member
Joined: 06 May 2009 Posts: 555

Posted: 18 Oct 2009 08:45:04 am Post subject: 


Bwyard wrote: Lbl BR
B→R
While fPart(Ans
10Ans
End
1+(R≠[escape][/escape]+(Ans<0)+int(log(abs(Ans→R
Disp ""
Output(4,4,"Fraction Form
Disp ""
Output(5,1,"(
Output(5,2,B
Output(5,2+R,"+
Output(5,3+R,i
Output(5,4+R,real(22,I)
length(real(22,I→H
Output(5,4+R+H,") While looking at your code, I realized you wern't using the routien by Weregoose correctly. You can use the Ans variable instead of R so it leaves R for the line after the loop. If you want to use another variable than Ans, you can use anything that's unimportant. (R is important there, so you can't use it) .
Last edited by Guest on 05 Jul 2010 07:52:10 am; edited 1 time in total 

Back to top 


Bwyard
Newbie
Joined: 28 Apr 2009 Posts: 17

Posted: 18 Oct 2009 11:47:56 am Post subject: 


yeah i did not know that so thanks, but i changed it from that to the decimal to fraction conversion. but yeah thanks alot for helping me. 

Back to top 


