2

In my TI BASIC program on TI 84 plus C, I have a line that says remainder((A/X),2). This creates a domain error every time the program runs. In the case of my tests, A/X is 4. remainder(4,2) works. 4->Z remainder(Z,2) works. If I pause the program and display (A/X) immediately before the remainder line, the result is certainly 4. (A/X)->Z remainder(Z,2) does not work. What could possibly be wrong with my code?

link to the code:

https://drive.google.com/open?id=0B07yHA0-EssLUjZOc0dxektwbUU

https://drive.google.com/open?id=0B07yHA0-EssLSFlNcFNWZm0zNDQ

  • 1
    The code snippet works for me. A domain error occurs if the divisor or dividend is either negative or not an integer (for example 4.0001). Could you please post the complete code? – Sister Fister Oct 09 '17 at 00:48
  • 1
    It would be useful to have it in text (not all of it though, it's quite long, just some relevant part) in [sourcecoder](https://www.cemetech.net/sc/) format – harold Oct 11 '17 at 21:23
  • The program you've linked works for me (with some minor modifications), but the `remainder()` function isn't used at all in it. Are you sure that this is the correct program? – Sister Fister Oct 12 '17 at 23:45
  • Apologies, I uploaded an old version. It should be fixed now. The relevant segment starts around "If S" – Matthew Foran Oct 13 '17 at 16:24
  • Which input values (function, bounds, ...) do you use to trigger the error? – Sister Fister Oct 13 '17 at 18:00
  • 1, 2, 3, then select simpson from the menu – Matthew Foran Oct 17 '17 at 12:11
  • side note: I think you should be using `(A - L) / theta`, since you want to start counting from the left bound. You are only coincidentally getting `A / theta` as an integer since `L - 0` (1) is a multiple of `R - L` (1). – Vaelus Dec 07 '17 at 17:10

1 Answers1

1

Here is a valid substitution for remainder().

2fPart(A/(2X))

This works because the general form, KfPart(A/K) takes the fractional part of A/K, which will be the same as remainder(A,K) if A is an integer. TI-BASIC doesn't always return an integer value. For example, logBASE(16,2) is ever so slightly less than 4. When we multiply by K, we change the range from being 0 to 1, to 0 to K.

Nothing is inherently wrong with your code, it is TI-BASIC that is sometimes wrong.

clevor
  • 28
  • 3