This is an archived, read-only copy of the United-TI subforum , including posts and topic from May 2003 to April 2012. If you would like to discuss any of the topics in this forum, you can visit Cemetech's Calculator Programming subforum. Some of these topics may also be directly-linked to active Cemetech topics. If you are a Cemetech member with a linked United-TI account, you can link United-TI topics here with your current Cemetech topics.

This forum is locked: you cannot post, reply to, or edit topics. General Coding and Design => Calculator Programming
Author Message
Newbie


Bandwidth Hog


Joined: 23 Jan 2004
Posts: 2247

Posted: 18 Oct 2009 12:58:08 pm    Post subject:

Does anyone know of an algorithm to grab the decimal part from division that could work with any language not using any built in commands other than straight arithmetic.

ie: 7 /3 = 2.3333333 and it grab the .33333333
Back to top
Galandros


Active Member


Joined: 29 Aug 2008
Posts: 565

Posted: 18 Oct 2009 01:10:18 pm    Post subject:

Newbie wrote:
not using any built in commands other than straight arithmetic.

That can be a challenge.

This seems tricky and I can't find/remember a way right now. I will be thinking on it. I am starting to doubt that exist a way...

Anyway this made me realize how to do a thing... Coding time!


Last edited by Guest on 18 Oct 2009 03:50:15 pm; edited 1 time in total
Back to top
Newbie


Bandwidth Hog


Joined: 23 Jan 2004
Posts: 2247

Posted: 18 Oct 2009 01:51:44 pm    Post subject:

Galandros wrote:
Newbie wrote:
other than straight arithmetic.

That can be a challenge.

This seems tricky and I can't find/remember a way right now. I will be thinking on it. I am starting to doubt that exist a way...

Anyway this made me realize how to do a thing... Coding time!



Thanks. Just so it doesn't sound confusing, I want it just using arithmetic. The way you quoted it, it seemed like I was asking for any way other than arithmetic. :biggrin:
Back to top
Builderboy2005


Advanced Newbie


Joined: 19 Apr 2009
Posts: 51

Posted: 18 Oct 2009 01:55:19 pm    Post subject:

well, if you are using a language that can cast to an integer, that might be a good way. Like, 7.333 would be cast to 7, and then its simple subtraction to get what you need. It does depend on the language thigh, what are you using?
Back to top
Newbie


Bandwidth Hog


Joined: 23 Jan 2004
Posts: 2247

Posted: 18 Oct 2009 02:06:39 pm    Post subject:

PHP, but it would be nice to know something to just works across everything.
Back to top
bfr


Member


Joined: 13 Feb 2006
Posts: 108

Posted: 18 Oct 2009 02:19:49 pm    Post subject:

Yeah, I was thinking what Builderboy2005 said. I think nearly every programming language should have some sort of floor/cast to integer method built-in. If it for some reason doesn't and you can only add, subtract, multiply, and divide, then you could get your result by calculating 7 mod 3 using only those operations, which equals 1, and then 1/3 is your result.

Last edited by Guest on 18 Oct 2009 02:20:44 pm; edited 1 time in total
Back to top
Weregoose
Authentic INTJ


Super Elite (Last Title)


Joined: 25 Nov 2004
Posts: 3976

Posted: 18 Oct 2009 03:39:52 pm    Post subject:

Here's a funky way that probably wouldn't be very useful in your case: [font="times new roman"]1/2 – arctan(cot(π x))/π

Theoretically, though, this only works for positive numbers that are not integer multiples of 1/2.

But if you have access to int(), floor(), mod(), round(), etc., there are many transformations that will net you fpart().

Last edited by Guest on 18 Oct 2009 03:41:11 pm; edited 1 time in total
Back to top
Newbie


Bandwidth Hog


Joined: 23 Jan 2004
Posts: 2247

Posted: 18 Oct 2009 04:48:12 pm    Post subject:

Weregoose wrote:
Here's a funky way that probably wouldn't be very useful in your case: [font="times new roman"]1/2 – arctan(cot(π x))/π

Theoretically, though, this only works for positive numbers that are not integer multiples of 1/2.

But if you have access to int(), floor(), mod(), round(), etc., there are many transformations that will net you fpart().


haaaaa. :biggrin: Like you and many others said, I'm probably better off just using the built in functions. PHP has round and mod from what I know as well as others probably, but thanks for your help. Didn't realize it would be this complex. Well I guess I sorta did because of how long I was trying to figure out a way with no results.

Thanks everybody.
Back to top
GloryMXE7
Puzzleman 3000


Active Member


Joined: 02 Nov 2008
Posts: 604

Posted: 18 Oct 2009 08:00:12 pm    Post subject:

well ypu could transform the fraction to a mixed number and take only the fraction part
ex 7/3 = 2 1/3
1/3 = .333333

but your probably better of with the built in functions though
Back to top
vanchagreen


Member


Joined: 20 Feb 2008
Posts: 136

Posted: 18 Oct 2009 10:36:26 pm    Post subject:

Going on Glory MXE7's post some pseudo code might be:


Code:
Repeat number<1
number-=1
End Loop
Display number
Back to top
Newbie


Bandwidth Hog


Joined: 23 Jan 2004
Posts: 2247

Posted: 19 Oct 2009 11:26:26 am    Post subject:

Quick question off topic though:

If I have a php page say: home.php and I want it to say home.php?page=1 how would I get ?page=1 in the url the first time some visits the page?
It's easy to have a link that someone can click and it does that, but what can be done the first time someone comes to the page to change the URL to say that?
Back to top
cjgone
Aw3s0m3


Active Member


Joined: 24 May 2006
Posts: 693

Posted: 20 Oct 2009 01:37:42 am    Post subject:

Redirect the page? Surprised
Back to top
FloppusMaximus


Advanced Member


Joined: 22 Aug 2008
Posts: 472

Posted: 21 Oct 2009 08:56:43 pm    Post subject:

If home.php is equivalent to home.php?page=1, why does it matter which URL you use?

As to the original question: you're really just asking how to implement the modulus operation. One way:

Code:
a := 1
while x >= a or x <= -a:
  a := a * 2
while a > 1:
  a := a / 2
  if x >= a then x := x - a
  if x <= -a then x := x + a


Last edited by Guest on 21 Oct 2009 08:59:21 pm; edited 1 time in total
Back to top
Lego


Advanced Newbie


Joined: 05 Feb 2010
Posts: 58

Posted: 02 Mar 2011 06:35:48 pm    Post subject:

don't know what php does if you write an float into an int, but in c you can do it like that
int x;
float y=7,33333;
x=y; now x = 7
then just to y=y-x so you geht y=0,33333


Edit: Sorry i haven't read the posted date Sad


Last edited by Guest on 02 Mar 2011 06:37:29 pm; edited 1 time in total
Back to top
Display posts from previous:   
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
    »
» View previous topic :: View next topic  
Page 1 of 1 » All times are UTC - 5 Hours

 

Advertisement