Taşma: +, +% ve +| Karşılaştırması
Hata oluşturan, saran ve doyuran matematik.
Taşma: +, +% ve +| Karşılaştırması, CoddyKit'te ücretsiz bir Zig Academy dersidir. Bu, 4 dersinin 2. dersidir. Aşağıdan dersin tamamını ücretsiz okuyabilir, sonra tarayıcıda yerleşik kod editörü ve 7/24 yapay zeka koçu ile uygulamalı olarak pratik yapabilirsin. Bu, Zig Academy öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. Zig Academy kursu toplamda 4 dersten oluşur.
Bu dersin bazı bölümleri henüz çevrilmemiş olup İngilizce olarak gösterilmektedir.
Numbers Have Limits
Every sized integer has a maximum it can hold. Push past it and you hit overflow, the moment a value tries to grow beyond its range.
Zig Catches Overflow
By default, the plain + operator traps overflow. In a safe build, going past the limit stops your program instead of corrupting the value.
var x: u8 = 255;
x = x + 1; // panics: overflowWhy Trapping Helps
A loud crash beats a silent wrong answer. Trapping turns a sneaky bug into an obvious failure you can find and fix fast.
Wrapping Math with +%
Sometimes you want the value to roll over on purpose. The +% operator wraps around, so 255 + 1 in a u8 becomes 0.
var x: u8 = 255;
x = x +% 1; // 0When Wrapping Is Right
Wrapping shines for counters, hashes, and checksums where roll-over is the intended behavior. You ask for it with the % suffix, never by accident.
Saturating Math with +|
The +| operator clamps to the limit instead of wrapping. A u8 at 255 stays 255, perfect for values that must not exceed a ceiling.
var x: u8 = 255;
x = x +| 1; // 255Three Choices, One Decision
So + traps, +% wraps, and +| saturates. You pick the behavior that matches your intent, making overflow handling explicit in your code.
The Same Trio for Subtraction
These suffixes are not just for addition. -, -%, and -| give you trapping, wrapping, and saturating subtraction the very same way.
var x: u8 = 0;
x = x -| 1; // 0And for Multiplication
Multiplication follows the pattern too: *, *%, and *|. The single rule, choose your overflow behavior, applies across the arithmetic operators.
const big = a *% b; // wrap on overflowDefault Builds Stay Safe
In Debug and ReleaseSafe modes, plain operators check for overflow. You only opt out where you have a real reason to wrap or saturate.
Intent Lives in the Code
Because each behavior has its own symbol, a reader sees your overflow intent at a glance. Nothing is assumed; the operator spells it out.
Quick Check
You want a u8 counter to roll over from 255 back to 0. Which operator?
Recap: Pick Your Overflow
Plain math traps, the % suffix wraps, and the | suffix saturates. Choose deliberately, and overflow is never a hidden surprise. 🛡️
Sıkça Sorulan Sorular
“Taşma: +, +% ve +| Karşılaştırması” dersi ücretsiz mi?
Evet — “Taşma: +, +% ve +| Karşılaştırması” dersin tüm metni burada web'de ücretsiz olarak okunabilir. Etkileşimli olarak pratik yapmak (yerleşik kod editörü ve 7/24 yapay zeka koçu) ve Zig Academy kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. Zig Academy kursu toplamda 4 dersten oluşur.
“Taşma: +, +% ve +| Karşılaştırması” dersinde ne öğreneceğim?
Hata oluşturan, saran ve doyuran matematik. Zig Academy ile uygulamalı kodu tarayıcıda doğrudan çalıştırarak pratik yaparsın ve 7/24 yapay zeka koçu dersi çalışırken sorularını yanıtlar.
Zig Academy öğrenmeye başlamak için deneyim gerekli mi?
Önceden deneyim gerekmez. CoddyKit'te Zig Academy, başlangıçtan ileri seviyeye kadar yapılandırıldığı için buradan başlayabilir veya başından başlayıp kendi hızında ilerleme yapabilirsin. Bu, 4 dersinin 2. dersidir.
“Taşma: +, +% ve +| Karşılaştırması” dersi ne kadar sürer?
Çoğu CoddyKit dersi yaklaşık 5–10 dakika sürer. Her biri kısa ve etkileşimli olduğu için sabit ilerleme yaparsın ve web ile uygulama arasında tam olarak bıraktığın yerden devam edebilirsin.
Bu Zig Academy dersinde kod yazıp çalıştırabilir miyim?
Evet. Her Zig Academy dersi yerleşik bir kod editörü içerir, bu sayede tarayıcıda gerçek kod yazıp çalıştırabilir ve anlık yapay zeka geri bildirimi alırsın — yerel kurulum gerekli değildir.
Bu kursun tüm dersleri
- Aritmetik ve Karşılaştırma İşleçleri
- Taşma: +, +% ve +| Karşılaştırması
- Bit Düzeyinde İşleçler
- Boole Mantığı ve Kısa Devre Değerlendirmesi