The built-in functions include round, floor, ceil, and trunc. Trunc rounds towards zero. For floats, the behavior of trunc is equivalent to the following:

float func trunc(float x)
  if x >= 0
    return floor(x)
  else
    return ceil(x)
  endif
endfunc

There is no equivalent function with < instead of >. In mathematics, I haven't even found a name for this. The best name that I could come up is "elong", a shortened version of elongate, as truncate is short for truncate.

Any comments?

The built-in functions include round, floor, ceil, and trunc. Trunc rounds towards zero. For floats, the behavior of trunc is equivalent to the following: ```` float func trunc(float x) if x &gt;= 0 return floor(x) else return ceil(x) endif endfunc ```` There is no equivalent function with &lt; instead of &gt;. In mathematics, I haven&#039;t even found a name for this. The best name that I could come up is &quot;elong&quot;, a shortened version of elongate, as truncate is short for truncate. Any comments?
 
0
reply

Yes, rarely, only in one of the Gaussian Integer coloring formulas or something similar.

(The email announcing your reply said that JVYV had replied.)

Yes, rarely, only in one of the Gaussian Integer coloring formulas or something similar. (The email announcing your reply said that JVYV had replied.)
edited Sep 23 '22 at 3:58 pm
 
0
reply

I think that's an effect of FPU rounding modes on x86. There are four total modes,

  • to nearest
  • towards zero
  • downward
  • upward

towards zero seems like the expected behavior of a truncation, since you'll always end up with the number before the decimal point as the result like you'd expect.

There's no actual "trunc" instruction in x87 or SSE (maybe there's a "fround" that avoids casting? I never messed with x87 much because it was a ridiculous mess) / AVX but casting to an integer and back will invoke FISTTP (SSSE3 but operating on x87 stack) / FISTP if the floating point x87 stack is in use and cause this rounding, or the SSE2 CVTTSD2SI can convert a double in a vector register or memory location to a truncated int in a GPR. I'm guessing most compilers generate that version for casts since everything that doesn't support SSE2 is effectively deprecated.

I think that&#039;s an effect of FPU rounding modes on x86. There are four total modes, - to nearest - towards zero - downward - upward towards zero seems like the expected behavior of a truncation, since you&#039;ll always end up with the number before the decimal point as the result like you&#039;d expect. There&#039;s no actual &quot;trunc&quot; instruction in x87 or SSE (maybe there&#039;s a &quot;fround&quot; that avoids casting? I never messed with x87 much because it was a ridiculous mess) / AVX but casting to an integer and back will invoke FISTTP (SSSE3 but operating on x87 stack) / FISTP if the floating point x87 stack is in use and cause this rounding, or the SSE2 CVTTSD2SI can convert a double in a vector register or memory location to a truncated int in a GPR. I&#039;m guessing most compilers generate that version for casts since everything that doesn&#039;t support SSE2 is effectively deprecated.
 
0
reply

One possibility of getting this would be to just use

trunc(z) + sign(z)
One possibility of getting this would be to just use ```` trunc(z) + sign(z) ````
 
0
reply

Yes, good idea, except sign( ) isn't a built-in function in UF. In my version of Gaussian Integer, I've used

if x >= 0
  return ceil(x)
else
  return trunc(x)
endif
Yes, good idea, except sign( ) isn&#039;t a built-in function in UF. In my version of Gaussian Integer, I&#039;ve used ```` if x &gt;= 0 return ceil(x) else return trunc(x) endif ````
edited Apr 5 '23 at 12:35 pm
 
0
reply
218
views
5
replies
4
followers
live preview
Enter at least 10 characters.
WARNING: You mentioned %MENTIONS%, but they cannot see this message and will not be notified
Saving...
Saved
All posts under this topic will be deleted ?
Pending draft ... Click to resume editing
Discard draft