Skip to content

Conversation

@kaetemi
Copy link
Contributor

@kaetemi kaetemi commented Oct 30, 2025

This replaces use of the global abs with std::abs.

The abs function declared outside of the std namespace is not required to have any of the C++ overloads defined. (Although it's also not precluded.)

Under Clang using the global abs with a larger integer type gives a truncation warning.

/home/kaetemi/llama.cpp/src/llama-quant.cpp:656:66: warning: absolute value function 'abs' given an argument of type 'const int64_t' (aka 'const long') but has parameter of type 'int' which may cause truncation of value [-Wabsolute-value]
  656 |                 gguf_set_val_u32(ctx_out.get(), o.key, (uint32_t)abs(o.val_i64));
      |                                                                  ^
/home/kaetemi/llama.cpp/src/llama-quant.cpp:656:66: note: use function 'std::abs' instead
  656 |                 gguf_set_val_u32(ctx_out.get(), o.key, (uint32_t)abs(o.val_i64));
      |                                                                  ^~~
      |                                                                  std::abs
1 warning generated.

Some standard libraries define the overloads globally, some don't. Recommended to always use the std:: functions to avoid anything unexpected.

See #15374 for further references.

This also was reported in the following issues:
#15044
#15254

This PR replaces the following incorrect PR:
#14209

@ggerganov ggerganov merged commit d739511 into ggml-org:master Oct 30, 2025
71 of 72 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants