Objective-C / C constant scalar value declarations -


i not see how adding l number makes difference. example if took number 23.54 , made 23.54l difference make , when should use l , not use l or other add ons that? doesn't objective-c know 23.54 long why make 23.54l in case?

if explain that'd great thanks!

actually, when number has decimal point 23.54 default interpretation it's double, , it's encoded 64-bit floating point number. if put f @ end 23.54f, it's encoded 32-bit floating pointer number. putting l @ end declares number long double, encoded 128-bit floating point number.

in cases, don't need add suffix number because compiler determine correct size based on context. example, in line

float x = 23.54; 

the compiler interpret 23.54 64-bit double, in process of assigning number x, compiler automatically demote number 32-bit float.

here's code play around with

nslog( @"%lu %lu %lu", sizeof(typeof(25.43f)), sizeof(typeof(25.43)), sizeof(typeof(25.43l)) );  int x = 100; float y = x / 200;   nslog( @"%f", y );  y = x / 200.0;     nslog( @"%f", y ); 

the first nslog displays number of bytes various types of numeric constants. second nslog should print 0.000000 since number 200 interpreted in integer, , integer division truncates integer. last nslog should print 0.500000 since 200.0 interpreted double.


Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -