0Pricing
Zig Academy · Ders

Kayan Nokta: f32 ve f64

Kesirli sayılarla çalışın.

Kayan Nokta: f32 ve f64, 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 with a Fraction

When you need decimals, Zig offers floating-point types. They store fractional values like 3.14 instead of whole numbers only.

f64 Is the Common Choice

The f64 type holds a double-precision float using 64 bits. It is the usual default when you want accuracy and plenty of range.

const pi: f64 = 3.14159;

f32 Trades Precision for Size

An f32 uses 32 bits. It saves memory and can be faster, but it stores fewer significant digits than an f64.

const ratio: f32 = 0.5;

Zig Has More Float Widths

Beyond f32 and f64, Zig also supports f16 and f128. You choose the width that balances precision against memory and speed.

Float Literals Need a Dot

A float literal includes a decimal point, like 2.0. Writing just 2 gives an integer, which is a different kind of value.

const half = 0.5;
const one = 1.0;

Scientific Notation Works Too

You can write very large or small floats with an exponent. The form 1.5e3 means 1.5 times ten to the third power, or 1500.

const big: f64 = 1.5e3;

Doing Float Math

The usual operators apply to floats. Division of two floats keeps the fractional part instead of throwing it away.

const result: f64 = 7.0 / 2.0; // 3.5

Floats Are Approximate

Floats cannot store every decimal exactly. Tiny rounding errors mean 0.1 plus 0.2 may not equal exactly 0.3.

Compare with a Tolerance

Because of rounding, avoid testing floats for exact equality. Check that the difference is smaller than a tiny threshold instead.

const close = @abs(a - b) < 0.0001;

Convert Int to Float

To turn an integer into a float you ask explicitly with @floatFromInt. Zig never mixes the two number kinds silently.

const n: i32 = 10;
const f: f64 = @floatFromInt(n);

Special Float Values

Floats can also represent infinity and not-a-number. These appear from operations like dividing by zero, and the std library names them.

Quick Check

You divide one float by another and want to keep the fractional result. What is true about floating-point math in Zig?

Recap

Use f64 for general decimals and f32 to save space. Remember floats are approximate, so compare with a tolerance and cast on purpose. 🎯

Sıkça Sorulan Sorular

“Kayan Nokta: f32 ve f64” dersi ücretsiz mi?

Evet — “Kayan Nokta: f32 ve f64” 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.

“Kayan Nokta: f32 ve f64” dersinde ne öğreneceğim?

Kesirli sayılarla çalışın. 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.

“Kayan Nokta: f32 ve f64” 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

  1. Boyutlandırılmış Tam Sayılar: i32, u8, usize
  2. Kayan Nokta: f32 ve f64
  3. bool, void ve Comptime Türleri
  4. Sayı Değişmezleri ve Alt Çizgiler
← Zig Academy Sayfasına Dön