Jump to content

math for dummies - I mean, for Weidu


Recommended Posts

How does Weidu have fractions? Say I want to edit the XP value field in .cre files with something like this pseudocode:


COPY_EXISTING_REGEXP GLOB ~*.cre~ ~override~
   READ_LONG 0x00xx xp
   SET new_xp = (xp / 5)
   PATCH_IF xp > 5 BEGIN
      WRITE_LONG 0x00xx new_xp
What happens if "new_xp" resolves to 12.5?
Link to comment

The READ_LONG is 0x0014.

Anyways, the weidu will write the number 12.5 to be 12. Even if it were 12.992... it still is 12.

I have this plenty with the Frankenstein that is the iispell mod function that I haven't released yet.


Also it should be remembered that the divisional remainder, though not shown in the whole number quotient is always factored in.. so you can easily get surprised by 2+2 = 5... as it could be 2(.3) + 2(.9) = 5(.2) if you don't take this into account.

Link to comment

To be clear, it's the integer division operation using / that returns only the whole number quotient. You can use the modulo operator % to determine the remainder of the division, if desired.


For example, 7 / 2 is 3 and 7 % 2 is 1. (7 divided by 2 is 3 with a remainder of 1.) You probably did long division with remainders in elementary school.


A handy thing to know is that X % 2 will tell you if X is an odd number: odd numbers will leave a remainder of 1, while even numbers will leave a remainder of 0.


Euclidean division

Link to comment


This topic is now archived and is closed to further replies.

  • Create New...