built-in

What is the advantage of GCC's __builtin_expect in if else statements?

空扰寡人 提交于 2019-12-17 05:16:15
问题 I came across a #define in which they use __builtin_expect . The documentation says: Built-in Function: long __builtin_expect (long exp, long c) You may use __builtin_expect to provide the compiler with branch prediction information. In general, you should prefer to use actual profile feedback for this ( -fprofile-arcs ), as programmers are notoriously bad at predicting how their programs actually perform. However, there are applications in which this data is hard to collect. The return value

Exponentials in python x.**y vs math.pow(x, y)

穿精又带淫゛_ 提交于 2019-12-17 05:01:14
问题 Which one is more efficient using math.pow or the ** operator? When should I use one over the other? So far I know that x**y can return an int or a float if you use a decimal the function pow will return a float import math print math.pow(10, 2) print 10. ** 2 回答1: Using the power operator ** will be faster as it won’t have the overhead of a function call. You can see this if you disassemble the Python code: >>> dis.dis('7. ** i') 1 0 LOAD_CONST 0 (7.0) 3 LOAD_NAME 0 (i) 6 BINARY_POWER 7

Giving array as parameter to a Jena built-in

£可爱£侵袭症+ 提交于 2019-12-14 03:16:58
问题 I need to create a new built-in for Jena. With this one I would like to be able to extract the minimum date from where it is. I just wondering if it is possible to give a class of datas to a built-in instead of just one parameter. Here is the bodyCall of my function : @Override public boolean bodyCall(Node[] args, int length, RuleContext context) { System.out.println("Entra"); checkArgs(length, context); BindingEnvironment env = context.getEnv(); Node n1 = getArg(0, args, context); Node n2 =

Why python allows to overwrite builtin constants?

南楼画角 提交于 2019-12-13 18:46:43
问题 Although True , False are builtin constants, the following is allowed in Python. >>> True = False >>> a = True >>> b = False >>> print a,b False False Any reference of why this is allowed? EDIT: This happens only in Python 2.x (as all pointed out). 回答1: Keep in mind that this only happens in versions of Python that were before python 3. This was part of Python's philosophy that everything should be dynamic. In fact in Python 2 True is not a keyword. It is a reference bound to a bool object .

Python: can isinstance(i, type(i)) evaluate to False?

帅比萌擦擦* 提交于 2019-12-13 17:02:28
问题 I am looking for something in the following piece of code so that the isinstance() check afterwards evaluates to True in any case: i = WonderfulClass() classinfo_of_i = something(i) isinstance(i, classinfo_of_i) # must evaluate to True If type is your answer, I'd be grateful if you explained why. Is type the real counterpart of isinstance ? Or, asked the other way round, can you think of a case where isinstance(i, type(i)) evaluates to False? This question arose in the context of the simple

Python: Is There a builtin that works similar but opposite to .index()?

你离开我真会死。 提交于 2019-12-13 09:24:48
问题 Just a forewarning: I just recently started programming and Python is my first language and only language so far. Is there a builtin that works in the opposite way of .index() ? I'm looking for this because I made a bool function where I have a list of ints and I want to return True if the given list of ints is a list of powers of some int x of the form [x^0, x^1, x^2, x^3, ...] and `False' otherwise. What I want to say in code is along the lines of: n >= 1 while the position(n+1) = position

What is the perl equivalent of MAX_INT?

一笑奈何 提交于 2019-12-12 10:29:29
问题 I am new to perl and seeking the lowest value in an @array . Is there some constant that represents a very large integer number? I know I could sort the array and take the beginning, but that seems to be a lot of wasted CPU cycles. What is an elegant solution to my problem in Perl? 回答1: In the general case, you can use undef to signal a non-existent value; perl scalars aren't restricted to holding just integers. That would be written: my $min; # undef by default for my $value (@array) { $min

Exclude __builtin__ module

匆匆过客 提交于 2019-12-12 06:38:46
问题 The __builtin__ module in Python clutters a developers namespace with lots of functions and classes that have very generic names (e.g. max , sum , id , hash etc.) that often get in the way of naming variables and when outside of a context-aware IDE one can accidentally overwrite a name without noticing. Is there a way to stop this module from being implicitly accessed from a certain file and require explicit imports instead? Something along the lines of: from __builtins__ import hash as

WebStorm 12 EAP - JavaScript debug configuration doesn't work with built-in webserver

两盒软妹~` 提交于 2019-12-12 03:07:42
问题 I am trying to start debugging session using built-in WebStorm server after I created a new JavaScript debug configuration. I am using this project: https://github.com/pauldessert/SeedTip.git I am experiencing this weird problem that all of my locally referenced .css and .js files: <link rel="stylesheet" href="css/reset.css"> <link rel="stylesheet" href="css/style.css"> <script src="js/map.js"></script> <script src="js/search.js"></script> ...could not be found/loaded by the browser. I show

bash caller builtin stops working from exported function, why?

梦想与她 提交于 2019-12-11 12:57:20
问题 I have very strange issues using bash and exported function to give me a reliable answer to the call of the builtin caller . Here's my setup to illustrate this issue: Bash script bar defines and exports function bar1 and bar2 . bar2 calls bar1 . Bash script bar then execute bash script foo which will call bar1 . The caller builtin will then break only after the call of bar1 . Is this normal ? can you explain why ? can you simplify the following code that exposes the issue ? To be perfectly