Skip to content

llama : use std::abs instead of abs#16853

Merged
ggerganov merged 1 commit intoggml-org:masterfrom
kaetemi:hotfix/clang-std-abs
Oct 30, 2025
Merged

llama : use std::abs instead of abs#16853
ggerganov merged 1 commit intoggml-org:masterfrom
kaetemi:hotfix/clang-std-abs

Conversation

@kaetemi
Copy link
Copy Markdown
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
Anico2 added a commit to Anico2/llama.cpp that referenced this pull request Jan 15, 2026
blime4 referenced this pull request in blime4/llama.cpp Feb 5, 2026
Seunghhon pushed a commit to Seunghhon/llama.cpp that referenced this pull request Apr 26, 2026
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